Java Program to Allocate and Initialize Super Class Members Using Constructor
A constructor in Java is a special method that is used to initialize an object. Whenever an object is created using the new keyword at least one construction is called. The constructor name must match with the class name and cannot have a return type. If there is no constructor available in the class in such a case java compiler provides a default constructor(no parameter constructor) by default.
Parameterized Constructor: The parameterized constructor is used to initialize the field of the class with our own values.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
constructor call Name of the student Nilesh Registration Number 2021806 constructor call Name of the student Bhaskar Registration Number 2021807
In a class hierarchy constructor are called according to the hierarchy, first parent class constructor will be invoked and then the child class constructor will be invoked
Hi I am parent constructor multiplication of two number 3 and 4 is 12 Hi I am child class constructor class field of x class is 5
Name of grand parent Pan Singh and he is 85 year old Name of parent M.S.Dhoni and he is 39 year old Name of child Ziva Dhoni and he is 5 year old