Home >Java >javaTutorial >Java Implicit Super Constructor Error: How to Fix \'Implicit super constructor... is undefined for default constructor\'?
Java Error: Implicit Super Constructor Undefined for Default Constructor
Q: Default Constructor Error with Subclass and Abstract Base Class
A Java developer encounters an error stating "Implicit super constructor BaseClass() is undefined for default constructor." after removing redundant constructors from subclasses. They wonder if it's possible to remove the constructors while still adhering to the template method pattern.
A: Construction and Default Constructors
The error arises because the base class (BaseClass) declares a constructor (public BaseClass(String someString)), disabling the default constructor (without arguments). When removing the constructor from the subclass (ACSubClass), the compiler inserts an implicit call to the no-argument constructor of the base class (super()) via the default constructor. Since BaseClass doesn't have a no-argument constructor, this is illegal.
Possible Solutions:
However, these solutions may not be feasible if the base class requires constructor arguments.
Additionally, consider refactoring the design:
The above is the detailed content of Java Implicit Super Constructor Error: How to Fix 'Implicit super constructor... is undefined for default constructor'?. For more information, please follow other related articles on the PHP Chinese website!