In Java inheritance, constructors are not inherited by subclasses, but the parent class constructor is always called first before the child class constructor, ensuring proper initialization of inherited members; this automatic execution is facilitated by the super() keyword, which Java calls by default during object creation.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Constructors Don't Inherit - Here's WhyAdded:
Hello everyone. Welcome back to Java Learning Hub for ICSC. Today we are going to see the role of constructors and inheritance when we are working in Java language. So this is our topic. Now let us see uh what we are going to do in this is we are going to understand how the constructors are going to work whenever it is under inheritance concept. So before for that we need to know about this few important points. What are those are constructors are not inherited by subasses. So we know that whenever we are talking about the inheritance concepts we will have two classes A and B. A is space class, B is derived class.
So more than one classes are required.
So what is what it is trying to say is we cannot yeah we cannot say that A cannot access the value of B.
A can access the value of B but B cannot access the value of A. Right? So that is what it is trying to say us. Next parent class constructor is called first. So obviously the base class constructor is called first then the subclass constructor is going to be called. Then let us see about the super keyword by how we can call the parent class. So we use a keyword called as super for calling the parent class.
And how it is possible? we need not write it. Java itself automatically calls the super constructor. Now where it is also helpful is it is also helpful when we are using or we say that object initialization whenever we are initializing the variable of or we initializing an object that time we will use it right. I hope you all are following me.
Uh please like, share and subscribe the channel and try to and see all the videos what I post and oh yeah I forgot to you all and um let us see an example sample example here. Here I have a parent class as class where I am using a constructor called as parent where we are going to display the parent class as parent class constructor message. Then we are closing the constructor default constructor it is and we are closing this class. Then we are taking another class by name child which is going to be extended by the keyword extends the base class. Our base class here is parent. So we are going to extend the parent here with the help of extend keyword. This question has been asked earlier and you need to know that the keyword which is used for calling the base class in a child class or derived class is extends.
Right? Here also we have a constructor by name child.
Here what we are doing we are displaying a message child class constructor. Then we are closing the class. We are closing sorry constructor then we are closing the class. So if you remember just now we have discussed it. We have I have said you that parent class constructor is called first. Here we have two constructors.
One is parent the other one is child. So whenever the Java has to call the constructors first it will call this parent constructor then it will call the child constructor. You just need to know those. Then we did not write any for calling we are not using call here. But if we need to call we are not going to use any keyword or any term or any constructor. By default it will call the super constructor initially. Now here what do we have? We have a main method followed by the main void main string ars.
Then we are creating an object of a child. So obj obj is an variable or initialization of the variable or object of base derived class or child class is equals to new child. Here child is a constructor.
Then whenever we are going to see the output our output will be parent class constructor child class constructor.
These are the two options we have right parent class constructor child class constructor. So whenever we are going to call we going to display the close to as the message. Now let us see about the relation. What we are going to do here we are going to create the child object.
As I have already said you that parent constructor execute first then child constructor executes and ensures inherited members are initialized properly. So it is of course that how we are going to initialize the inherited members.
So lastly but not the least we can say conclude this as constructors helps initialize parent and child class objects in the correct order during inheritance.
So constructors are the one which are going to help in initialization of the parent and child class objects in the order during inheritance. Correct order is the first the parent class gets inherited then the uh sorry first parent class is going parent constructor is going to be called and then the child constructor is going to be called. I hope you have understood this concept and if in case you have any queries you can comment me comment below and if you have any doubts you can go through this and still if you feel don't feel feel free to message and see the information I hope you all might have understood this and for other videos like share and subscribe my channel Java Learning Hub for ICS_4_IC CC for more videos like this so that you can understand the concept easily and thank you very much for joining.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 viewsโข2026-05-28
How agent o11y differs from traditional o11y โ Phil Hetzel, Braintrust
aiDotEngineer
450 viewsโข2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation๐ฏโ
LearnwithSahera
1K viewsโข2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 viewsโข2026-05-29
Search Algorithms Explained in 60 Seconds! ๐ค๐จ
samarthtuliofficial
218 viewsโข2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 viewsโข2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 viewsโข2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 viewsโข2026-06-01











