Menu
Question Index
...

What will be the output of the following program?

public class MultiLevelDefaultConstructors {
    public static void main(String arg[]) {
        System.out.println("---------------");
        A a = new A();
        System.out.println("---------------");
        B b = new B();
        System.out.println("---------------");
    }
}
class A {
    A() {
        System.out.println("Created A");
    }
}
class B extends A {
    B() {
        System.out.println("Created B");
    }
}


---------------
Created A
---------------
Created A
Created B
---------------
---------------
Created A
---------------
Created B
---------------
Compilation Error
Runtime 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