# Implicit super constructor classes.Mover() is undefined. Must explicitly invoke another constructor

**URL:** <https://discourse.processing.org/t/implicit-super-constructor-classes-mover-is-undefined-must-explicitly-invoke-another-constructor/37683>\
**Category:** Beginners\
**Created:** [June 22, 2022, 2:51am UTC](https://discourse.processing.org/t/implicit-super-constructor-classes-mover-is-undefined-must-explicitly-invoke-another-constructor/37683 "2022-06-22T02:51:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![BeshooD](https://avatars.discourse-cdn.com/v4/letter/b/c89c15/32.png) [@BeshooD](https://discourse.processing.org/u/BeshooD)\
**Post date:** [June 22, 2022, 2:51am UTC](https://discourse.processing.org/t/implicit-super-constructor-classes-mover-is-undefined-must-explicitly-invoke-another-constructor/37683/1 "2022-06-22T02:51:15Z")

</div>

Not sure what this message means, can I get some help?

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [June 22, 2022, 5:30am UTC](https://discourse.processing.org/t/implicit-super-constructor-classes-mover-is-undefined-must-explicitly-invoke-another-constructor/37683/2 "2022-06-22T05:30:05Z")

</div>

Hi @BeshooD ,

Quite less Information provided in your post, but the message means you have s.th. like this

```auto
public class BaseClass { 
    public BaseClass(String aParam) { 
// ...
    }
} 

public class SubClass extends BaseClass {
    public SubClass(String aParam, int anotherParam) {
// ... if no explicit super is called it tries to call implicit super();
    } 
}

```

as you see, the BaseClass is not providing a default constructor (without patameters), so the SubClass has to call the constructor of the BaseClass (with parameters)

```auto
public class BaseClass { 
    public BaseClass(String aParam) { 
// ...
    }
} 

public class SubClass extends BaseClass {
    public SubClass(String aParam, int anotherParam) {
        super(aParam);
    } 
}

```

See [super](https://docs.oracle.com/javase/tutorial/java/IandI/super.html) for more information…

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [June 22, 2022, 9:24am UTC](https://discourse.processing.org/t/implicit-super-constructor-classes-mover-is-undefined-must-explicitly-invoke-another-constructor/37683/3 "2022-06-22T09:24:48Z")

</div>

Add an explicit default constructor to your base class like this

> [@mnse](#):
>
> ```auto
> // modified
> public class BaseClass { 
> public BaseClass() { 
> // Explicit default constructor
> }
> 
> public BaseClass(String aParam) { 
> // ...
> }
> } 
> 
> ```

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [June 22, 2022, 9:50am UTC](https://discourse.processing.org/t/implicit-super-constructor-classes-mover-is-undefined-must-explicitly-invoke-another-constructor/37683/4 "2022-06-22T09:50:14Z")

</div>

Hi,

> [@quark](#):
>
> Add an explicit default constructor to your base class like this

I think this isn’t always a solution, in case if the _aParam_ is mandatory for the base class to work properly …

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [June 22, 2022, 10:08am UTC](https://discourse.processing.org/t/implicit-super-constructor-classes-mover-is-undefined-must-explicitly-invoke-another-constructor/37683/5 "2022-06-22T10:08:21Z")

</div>

Your code is correct because you are calling `super(aParam);` so will it will look for a constructor `BaseClass(String)`. I should have studied your code more closely before replying. 😉

If the SubClass constructor does _not call_ a specific super class constructor the the BaseClass must have an explicit default constructor. This is shown in the sketch below. If you remove the default base constructor then it won’t work and you get the error reported.

```auto

void setup() {
  BaseClass obj = new SubClass("Jenifer", 21);
  println(obj);
}

public class BaseClass { 
  String name;
  int age;

  public BaseClass() { 
    // explicit default constructor
  }

  public BaseClass(String aParam) { 
    // ...
  }
} 

public class SubClass extends BaseClass {

  public SubClass(String aParam, int anotherParam) {
    name = aParam;
    age = anotherParam;
  } 

  public String toString() {
    return name + " aged " + age + " years";
  }
}

```

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [June 22, 2022, 1:08pm UTC](https://discourse.processing.org/t/implicit-super-constructor-classes-mover-is-undefined-must-explicitly-invoke-another-constructor/37683/6 "2022-06-22T13:08:26Z")

</div>

> [@quark](#):
>
> If the SubClass constructor does _not call_ a specific super class constructor the the BaseClass must have an explicit default constructor

Due to lack of further information from the question I assumed BeshooD made a base class named Mover with a construcor with parameter(s) and not calling them accordingly in the sub class. So I made my example depending on that presumption.  
For the rest I’ve re-linked the java tutorial about [super](https://docs.oracle.com/javase/tutorial/java/IandI/super.html), which says …

> **Note:** If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass. If the super class does not have a no-argument constructor, you will get a compile-time error. `Object` _does_ have such a constructor, so if `Object` is the only superclass, there is no problem.

😉

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [June 22, 2022, 3:11pm UTC](https://discourse.processing.org/t/implicit-super-constructor-classes-mover-is-undefined-must-explicitly-invoke-another-constructor/37683/7 "2022-06-22T15:11:58Z")

</div>

The whole thing can be quite complicated but this error can easily be avoided by

1. Include a default constructor (no parameters) in the base class even if you don’t think you need it.
2. If a child class constructor calls a base class constructor with `super(parameter_list)` then there must be a base class constructor with matching parameter list
3. If a child class constructor calls the default base class constructor with `super()` then the base class _must have an explicit default constructor_

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [June 22, 2022, 4:04pm UTC](https://discourse.processing.org/t/implicit-super-constructor-classes-mover-is-undefined-must-explicitly-invoke-another-constructor/37683/8 "2022-06-22T16:04:51Z")

</div>

Hi @quark ,

In principle I don’t want keep this thread unnecessarily open. But this isn’t true …

> [@quark](#):
>
> Include a default constructor (no parameters) in the base class even if you don’t think you need it.

Simplest example would be the most of the contributed libraries, which have as mandatory parameter the parent PApplet to get proberly initialized. Imagine they make a default constructor without attributes, you can successfully run the sketch but run into runtime error, as the object can be created but can not be used as not initialized. Sure, you can make a default constructor and throw an exception, but imho that would be quite silly …  
So, it would be better to have no default constructor that it would run into build error and it is clear to see that it can’t be used that way! eom.

Cheers  
— mnse

PS: Ok! Just one more sentence. There are circumstances which makes it mandatory to have a default constructor… but not always 🙂

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [June 22, 2022, 4:24pm UTC](https://discourse.processing.org/t/implicit-super-constructor-classes-mover-is-undefined-must-explicitly-invoke-another-constructor/37683/9 "2022-06-22T16:24:02Z")

</div>

The default constructor would be used to set default values for the class so in my example we could use either

```auto
public class BaseClass { 
  String name = "default name";
  int age = 0;

  public BaseClass() { 
    // explicit default constructor does nothing
  }

} 

```

or

```auto
public class BaseClass { 
  String name = "default name";
  int age = 0;

  public BaseClass() { 
    // explicit default constructor initialises attributes
    name = "default name";
    age = 0;
  }

} 

```

Every class definition should be autonomous which means they should initialise their own attributes. Sub classes should also initialise their own attributes (if any) and those of the parent class either directly or better still by calling a super constructor.

So I didn’t lie ☹ I just didn’t tell everything. Inheritance is a major topic in OO programming and would have its own chapter(s) in a text book. Can’t possibly cover every aspect here.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [June 22, 2022, 4:52pm UTC](https://discourse.processing.org/t/implicit-super-constructor-classes-mover-is-undefined-must-explicitly-invoke-another-constructor/37683/10 "2022-06-22T16:52:20Z")

</div>

Well! Let’s stop here, because I agree that it would hardly be possible to cover the whole OO topic by this thread.

Nevertheless, a nice conversation… ​:grin:

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [June 22, 2022, 10:59pm UTC](https://discourse.processing.org/t/implicit-super-constructor-classes-mover-is-undefined-must-explicitly-invoke-another-constructor/37683/11 "2022-06-22T22:59:49Z")

</div>

As @mnse mentioned, the most important class PApplet doesn’t have any constructor definition!

All “.pde” files are concatenated as 1 “.java” file and wrapped up as a PApplet subclass.

There’s also no need to call **super()** either when we create our own PApplet subclass for multi-window sketches.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [June 23, 2022, 5:15am UTC](https://discourse.processing.org/t/implicit-super-constructor-classes-mover-is-undefined-must-explicitly-invoke-another-constructor/37683/13 "2022-06-23T05:15:29Z")

</div>

Post deleted because it’s too early in the morning and I should have read the post more carefully. 😁
