Page 1 of 1

About Question com.enthuware.ets.scjp.v6. 2 .332 :

Posted: Wed Jun 24, 2015 11:50 pm
by richivarma

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; } }
The progarm will fail to compile.
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

Re: About Question com.enthuware.ets.scjp.v6.2.332 :

Posted: Thu Jun 25, 2015 12:40 am
by admin
Did you try to compile and run it? What did you find?