A
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");
}
}
public class Test{
public static void main(String... args){
A b = new B();
newValue(b);
}
public static void newValue(A a){
if(a instanceof B){
((B)a).printValue();
}
}
}
public void printValue(){
System.out.println("A");
}
}
class B extends A{
public void printValue(){
System.out.println("B");
}
}
public class Test{
public static void main(String... args){
A b = new B();
newValue(b);
}
public static void newValue(A a){
if(a instanceof B){
((B)a).printValue();
}
}
}
- Correct Answer - Option(B)
- Views: 4
- Filed under category Java
- Hashtags:
Discusssion
Login to discuss.