Java Question
class A {
public int f() {return 0;}
public int g() {return 3;}
}
class B extends A{
public int f() {return 1;}
public int g() {return f();}
class C extends B {
public int f() {return 2;}
A ref1 = new C();
B ref2 = (B) ref1;
System.out.println(ref2.g());
What is the answer?
1) The program will fail to compile
2) The program will compile without error and print 0 when run
3)The program will compile without error and print 1 when run
4)The program will compile without error and print 2 when run
5)The program will compile without error and print 3 when run
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here