JAVA Programming :: Basic Concepts - Discussion
Home > JAVA Programming > Basic Concepts > MCQs Questions Discussion
34 / 64
What is the output for the below code?
public class A {
int add(int i, int j){
return i+j;
}
}
public class B extends A{
public static void main(String argv[]){
short s = 9;
System.out.println(add(s,6));
}
}
public class A {
int add(int i, int j){
return i+j;
}
}
public class B extends A{
public static void main(String argv[]){
short s = 9;
System.out.println(add(s,6));
}
}
ACompile fail due to error on line no 2
BCompile fail due to error on line no 9
CCompile fail due to error on line no 8
D15
Answer: Option (Login/Signup)
Show Explanation
Asked In ::
STEP-BY-STEP
Cannot make a static reference to the non-static method add(int, int) from the type A. The short s is autoboxed correctly, but the add() method cannot be invoked from a static method because add() method is not static.
Read Full Answer
Report Error
Please Login First Click Here