Computer Science, asked by varsha1108, 1 year ago

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​

Attachments:

varsha1108: I want what is invoking methods and want to understand how that program is made
Anonymous: invoking a method means generally calling a method
varsha1108: ok
varsha1108: but how to use and make s program
ranjan143nyk: hii
ranjan143nyk: @varsha
varsha1108: hi
varsha1108: @ranjan
ranjan143nyk: how r u ?
ranjan143nyk: r u on @insta?

Answers

Answered by Anonymous
3

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 ↓↓ .


varsha1108: what is the use of return
Anonymous: to return the value to the function caller
varsha1108: ok
varsha1108: an u give me an example
Anonymous: I already wrote the code snippet .
varsha1108: what is snippet
Anonymous: I wrote the example already in my answer . See it .
Answered by jyotisikhadash2
2

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);

}

}


jyotisikhadash2: please mark me as the brainliest
Similar questions