Can Constructors be Inherited in Java



No, constructors cannot be inherited in Java.

In inheritance sub class inherits the members of a super class except constructors.

In other words, constructors cannot be inherited in Java therefore, there is no need to write final before constructors.

Example

public interface InterfaceTest {
   public InterfaceTest(){
   }
   public abstract void display();
   public abstract void show();
}

Still, if you try to write constructors in an interface it will generate a compile time error.

Error

C:\Sample>javac InterfaceTest.java
InterfaceTest.java:2: error: <identifier> expected
InterfaceTest(){
             ^
1 error
C:\Sample>
Updated on: 2019-07-30T22:30:20+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements