interface cannot have constructor in java, because interface not have any instance member so nothing to construct. Now the question comes how interface can be inherited without constructor because subclass constructor call super class constructor. We have two cases here. First case, interface extends other interface: in this situation there is no issue because as we know that no interface have constructor and that’s why no super class constructor will be called. Second case, a class implements an interface: in this situation there is no inheritance because class implements interface not extends interface.
Java interview questions on Inheritance
- Why multiple inheritance is not supported in java?
- How to implement multiple inheritance in java?
- Are interfaces also inherited from Object class?
- Why an interface cannot have constructor in java?
- How do you restrict a member of a class from inheriting to it’s sub classes?
- Can a class extend itself in java?
- Are constructors inherited in java?
- What happens if both superclass and subclass have a field with same name?
- Are static members inherited to subclasses in java?