0% found this document useful (0 votes)
18 views1 page

Calling Cons

The document demonstrates the order of constructor calls in a class hierarchy. It defines a superclass A and two subclasses B and C, with each constructor printing a message upon instantiation. When an instance of C is created, it triggers the constructors of A, B, and C in that order, displaying their respective messages.

Uploaded by

sm2395
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

Calling Cons

The document demonstrates the order of constructor calls in a class hierarchy. It defines a superclass A and two subclasses B and C, with each constructor printing a message upon instantiation. When an instance of C is created, it triggers the constructors of A, B, and C in that order, displaying their respective messages.

Uploaded by

sm2395
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// Demonstrate when constructors are called.

// Create a super class.


class A {
A() {
System.out.println("Inside A's constructor.");
}
}

// Create a subclass by extending class A.


class B extends A {
B() {
System.out.println("Inside B's constructor.");
}
}

// Create another subclass by extending B.


class C extends B {
C() {
System.out.println("Inside C's constructor.");
}
}

class CallingCons {
public static void main(String args[]) {
C c = new C();
}
}

You might also like