Menu
Topics Index
...
`

Constructor


If you need explanation Read this topic

If you need Answer Take test on this topic

Constructor
What will be the output of the following program?
class ConstructorsTest {
    public static void main(String[] args) {
        T u = new T();
        T u1 = new T(1);
        I v = new I();
        I v1 = new I(1);
        J t = new J();
        J t1 = new J(1);
    }
}
class T {
    I v = new I();
    T() {    System.out.print("t");    }
    T(int i) {    System.out.print("T");    }
}
class I {
    I() {    System.out.print("I");    }
    I(int i) {    System.out.print("i");    }
}
class J extends I {
    J() {    System.out.print("j");    }
    J(int i) {    System.out.print("J");    }
}

A. ITItiIIJIj
B. ItITIiIjIJ
C. ItITIiIJIj
D. Some other output
E. Compilation Error or Runtime Error
Topic: Inheritance And Constructors In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is : B, because T class constructor having constructor I().. so the output is " ItITIiIjIJ ".

Posted by Mallikarjuna Rao    2014-01-27 12:50:41


B.is the answer. as we are calling class T using u which in turns calls I without parameter prints I returns and prints t then again same takes place but with prmtrs and so on

Posted by Shabaaz Shaikz    2014-01-27 12:57:14


Congratulations Mallikarjuna Rao. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-01-28 04:05:02


© meritcampus 2019

All Rights Reserved.

Open In App