Menu
Question Index
...

What will be the output of the following program?

class Constructors {
    public static void main(String[] args) {
        new A(3);
        new B(5, 6);
        new B(6, 7).C(1, 2, 3);
        new C(3, 3, 4).B(4, 5);
        new C(1, 1, 1);
    }
}
class A {
    A(int i) {    print(i * 2);    }
    void print(int i) {    System.out.print(i + " ");    }
}
class B extends A {
    B(int j, int k) {
        super(j);
        print(k * 4);
    }
    void C(int j, int k, int l) {    print(j + k + l - 3);    }
}
class C extends B {
    C(int j, int k, int l) {
        super(j, k);
        print(l - 3);
    }
    void B(int i, int k) {    print(i * 6);    }
}


6 10 24 12 28 2 3 6 12 1 8 20 24 2 4 -2
6 10 24 12 28 3 6 12 1 24 2 4 -2
Some other output not shown here
Compilation Error

Doubts

Problems

Topic: Inheritance And Constructors In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App