A

Admin • 828.03K Points
Coach

Q. What will be the output for the below code ?

Code:
class A{
public void printValue(){
System.out.println("A");
}
}
class B extends A{
public void printValue(){
System.out.println("B");
}
}

1. public class Test{
2. public static void main(String... args){
3. A b = new B();
4. newValue(b);
5. }
6. public static void newValue(A a){
7. if(a instanceof B){
8. ((B)a).printValue();
9. }
10. }
11. }
  • (A) A
  • (B) B
  • (C) Compilation fails with an error at line
  • (D) Compilation fails with an error at line 8
  • Correct Answer - Option(B)
  • Views: 13
  • Filed under category Java
  • Hashtags:

No solution found for this question.
Add Solution and get +2 points.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.