Can an Interface have a constructor? Why or why not?
Last updated
No. A traditional interface cannot be instantiated and has no instance state, so there is nothing for a constructor to initialize.
The implementing class's constructor initializes the object, and interface constants are static (initialized at the type level).
By contrast, an abstract class can have a constructor (called via
super()) because it can carry state.
- https://medium.com/javarevisited/can-we-have-a-constructor-in-an-interface-why-or-why-not-063ae3055546
- https://www.geeksforgeeks.org/java/why-java-interfaces-cannot-have-constructor-but-abstract-classes-can-have/
- https://www.tutorialspoint.com/article/why-an-interface-doesn-t-have-a-constructor-whereas-an-abstract-class-have-a-constructor-in-java