About Question com.enthuware.ets.scjp.v6. 2 .332 :
Posted: Wed Jun 24, 2015 11:50 pm
Code: Select all
public class TestClass
{
public static void main(String args[ ] )
{
A o1 = new C( );
B o2 = (B) o1;
System.out.println(o1.m1( ) );
System.out.println(o2.i );
}
}
class A { int i = 10; int m1( ) { return i; } }
class B extends A { int i = 20; int m1() { return i; } }
class C extends B { int i = 30; int m1() { return i; } }
Class cast exception at runtime. (Actual correct answer main throw Excpetion)
It will print 30, 20. (Correct Answer - Green)
It will print 30, 30.
It will print 20, 20.
Please check and suggest