Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

implicit super constructor Person() is undefined. Must explicitly invoke another constructor?

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) {      }  } 
like image 249
sirnomnomz Avatar asked Apr 30 '14 18:04

sirnomnomz


1 Answers

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.

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.

like image 116
pxm Avatar answered Oct 02 '22 13:10

pxm