what are in voking methods
plz explain me step by step the above pic
plz answer only if u r knowing no spam or other website information
Answers
Invoking a method means to call a method Let me explain with code because theory can only be understood if explained properly .
class any
{
public static void main(String args[])
{
int num = 5;
int result = square(num);
System.out.print(result);
}
int square(int num)
{
return num*num;
}
}
Explanation:
The part of the code that is bolded is just calling the function . The function / method is invoked or called from that statement .
Now imagine that instead of int num in the method parameter , I wrote String , then there would be an error .
So the actual parameter and the formal parameters should match in their datatypes otherwise there would be compilation error .
If you have any doubts , comment ↓↓ .
Invoking a method means calling a method..
I too would like you to understand the program first..
class abc
{
int sum( int a, int b)
{
int s=0;
s=a+b;
return s; // the return statement
is used to return the sum of a
and b to the calling function
}
public static void main(String
args[])
{
abc ob = new abc();// creates an
object of the class abc
int b;//creating a variable to call
the method sum as the function
is a return type of function
b=ob.sum(5,7);// using the
object to call the method sum
System.out.println("Sum of two
numbers =" + b);
}
}