OOPs 1

Ques 17: Given: 
 class One {
    public One() { System.out.print(1); }
 } 
class Two extends One {
    public Two() { System.out.print(2); }
 }
 class Three extends Two {
    public Three() { System.out.print(3); }
 }
 public class Numbers{
    public static void main( String[] argv ) { new Three(); }
 }

What is the result when this code is executed?
A. 1
B. 3
C. 123
D. 321
E. The code runs with no output.
Answer: C

4 comments:

  1. May I know what is the logic behind it?

    ReplyDelete
  2. Base class constructor is called first and then derived class constructor.

    ReplyDelete
  3. whenever any class's constructor is called..then its called parent class's constructor if any...

    ReplyDelete
  4. A Sub-Class Constructor always calls it's super class constructor.

    ReplyDelete