skk skk - 2 years ago 451
Java Question

Java error: Implicit super constructor is undefined. Must explicitly invoke another constructor

I have a BaseClass in a external jar, it has a constructor setting Implementation class(JerseyClientImpl) to jerseyClient.

public BaseClass(AuthDetails auth, String ID) {
this.jerseyClient = new JerseyClientImpl(auth);

I am extending the BaseClass to set my own Implementation class to jerseyClient , but i am getting the error mentioned. Changing the BaseClass to add default constructor is not in my control as i said its an external jar.Can you suggest how can i overcome this error.

Answer Source

Since BaseClass has a non default constructor, it doesn't have the automatically generated parameterless default contstructor.

Therefore your sub-class can't rely on the default constructor (since it won't be able to call the non-existing default constructor of the base class), so your sub-class must have an explicit constructor that calls the constructor of the base class.

Either a constructor with the same parameters :

public SubClass(AuthDetails auth, String ID) {

Or a constructor without parameters that gives default values for the base-class's constructor :

public SubClass() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download