super keyword for calling constructor function of the parent class in a multilevel hierarchy of level 3
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Explain the use of super keyword for calling constructor function of the parent class in a multilevel hierarchy of level 3
super keyword:
The "super" keyword in Java allows accessing the constructor of the immediate parent class (or superclass).
In multilevel inheritance, the super keyword is used in subsequent subclasses to call their respective superclass constructor. We need to create an object of the lowest subclass in order to invoke its constructor only. The constructor of the remaining superclasses will be invoked using super keyword.
Consider the following multilevel hierarchy of level 3:
class A {
A() { } // class A constructor
}
class B extends A {
B() {
super(); //it will call constructor of class A that is parent class of B
}
}
class C extends B {
C() {
super(); //it will call constructor of class B that is parent class of C
}
}
//create object of class C to invoke a constructor of class C
C obj = new C();
Step by step
Solved in 2 steps with 1 images