You cannot inherit a constructor. That is, you cannot create a instance of a subclass using a constructor of one of it's superclasses. One of the main reasons is because you probably don't want to overide the superclasses constructor, which would be possible if they were inherited. By giving the developer the ability to override a superclasses constructor you would erode the encapsulation abilities of the language.
constructors are not inherited.You can call the superclass constructor with the help of super() from derived class.
Yes a subclass can call a super class constructors by using the keyword super,by using super it will call the super class which in turn the super class constructors.
1:- We can call the super class constructor by the use of super keyword at the first line inside the constructor and giving the parameters to it.
2:- If a subclass contain a no-args constructor(NO argument constructor) then the call to super is done automaticly in the first line of subclass constructor by default and call the super class no -args constructor.
eg:- class A{ A(){ s.o.p("A"); } } class B extends A{ B(){ s.o.p("B"); } } class Z{ psvm(String[]args) { B b=new B(); } } execution- B()->A()->B() output:- A B
First constructors are not methods...they do not define any functionality. Inheritance is done to reuse the functionality(methods).So even constructors have modifiers private,public,default,protected. If we make the constructor as private then the sub class can not create object with no-arg constructor.
Basically constructors are used to create a instance of class and pass some values to member variables, before creating a object of that class. And constructors are not a methods to override the functionality, so the purpose of inheriting the constructor is useless. And by java constructors cannot be inherited they can only be accessed by using the keyword called super.