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));
}
}
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));
}
}
A. The sum of x and y is 9
B. The sum of x and y is 45
C. does not compile
D. None of the above
Answer: Option C
Solution(By Examveda Team)
Return type of method display is int and we are trying to return string.
Join The Discussion
Comments ( 2 )
Related Questions on Constructors and Methods
What is a constructor in Java?
A. A special method to create instances of classes
B. A method used for mathematical calculations
C. A method to perform string manipulations
D. An exception handling mechanism
In Java, which method is automatically called when an object is created?
A. start()
B. main()
C. init()
D. constructor()
What is method overloading in Java?
A. Defining multiple methods with the same name in the same class
B. Calling methods from another class
C. Using methods to load data from a file
D. Running methods in parallel threads
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
galat hai 9 hoga