Computer Applications
When a method returns the value, the entire method call can be assigned to a variable. Do you agree with the statement?
User Defined Methods
60 Likes
Answer
Yes, when a method returns a value, we can assign the entire method call to a variable. The given example illustrates the same:
public class Example {
public int sum(int a, int b) {
int c = a + b;
return c;
}
public static void main(String args[]) {
Example obj = new Example();
int x = 2, y = 3;
int z = obj.sum(x, y);
System.out.println(z);
}
}
Answered By
38 Likes
Related Questions
Define a method. What is meant by method prototype?
What are the two ways of invoking methods?
When a method is invoked how many values can be returned from the method?
Debug the errors and rewrite the following method prototypes:
(a) int sum(x,y);
(b) float product(a,int y);
(c) float operate(int x, float=3.4);
(d) float sum(int x,y);