ExamVeda
Login
Home
Constructors and Methods
?

What is the output of the program?
class Test{ 
        public int display(int x, int y){ 
                return ("The sum of x and y is " + x + y); 
        } 

        public static void main(String args[]){ 
                Test test = new Test();
                System.out.println(test.display(4,5)); 
        } 
}

Answer & Solution
Correct Answer: Option C

Return type of method display is int and we are trying to return string.

Examveda
Question posted by Examveda
Community

Join the Discussion

2 Comments
Janagamwar Krishna
Janagamwar Krishna 8 years ago
Hi, Mohit Khare,
The answer given in the question was correct and
For the program below Answer will be 9
public class Test {
public int display (int x, int y){
return (x+y);
}
public static void main (String[] args){
Test test=new Test();
System.out.println("The sum of the x and y is :"+test.display(4,5));
}
}
Answer:
$javac Test.java
$java -Xmx128M -Xms16M Test
The sum of the x and y is :9
Mohit Khare
Mohit Khare 9 years ago
galat hai 9 hoga