Using the super keyword for constructors

Let's use the super keyword for constructors in this section. We'll use the previous example here too.

In the parentDemo class, we define a constructor, parentDemo(), and add a print statement to print: Parent class constructor.

In childDemo, we define a constructor childDemo() and add a print statement to print: Child class constructor. If we want to use the parentDemo class constructor in the childDemo class, we add the super() method in the childDemo() constructor. This makes the controller invoke the constructor in the parentDemo class.

There's an important rule we need to follow when working with constructors: whenever you use a super constructor in a child constructor, it should always be the ...

Get Hands-On Automation Testing with Java for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.