I am working on a project and i am getting the error "implicit super constructor Person() is undefined. Must explicitly invoke another constructor" and i don't quite understand it.
Here is my person class:
public class Person {
public Person(String name, double DOB){
}
}
And my student class when trying to implement the person class, and giving it an instructor variable.
public class Student extends Person {
public Student(String Instructor) {
}
}
This is how I achieved it (in my case the superclass was Team and the subclass was Scorer):
When creating a subclass constructor, if you don't explicitly call a superclass constructor with
super
, then Java will insert an implicit call to the no-arg "default" superclass constructor, i.e.super();
.However, your superclass
Person
doesn't have a no-arg constructor. Either supply an explicit no-arg constructor inPerson
or explicitly call the existing superclass constructor in theStudent
constructor.You need to make a
super
call to your defined constructor:You can't just call
super()
because that constructor is not defined.Reference: http://docs.oracle.com/javase/tutorial/java/IandI/super.html : (See under section 'SubClass Constructors')
So whenever dealing with parameterized constructors make a
super(parameter1, parameter2 ..)
call to the parent constructor. Also this super() call should be the FIRST line in your constructor block.you can't create an instance without calling a constructor of its super class. And the jvm doesn't know how to call Person(String, double) from your Student(String) constructor.