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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
richivarma
Posts: 2
Joined: Fri Jun 19, 2015 9:45 pm
Contact:

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

Post 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
Last edited by admin on Thu Jun 25, 2015 12:41 am, edited 2 times in total.
Reason: Please put code inside [code] [/code]

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Did you try to compile and run it? What did you find?

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests