java constructor in class cannot be applied to given types

Add super(NAME_IN_STRING_TYPE,YEAR_OF_BIRTH_IN_INT_TYPE); as a first statement in your subclasse's constructor like

Student constructor

Student()
{
super("name", 1970); // String,int arguments passed
 //task.
}

Staff constructor

Staff()
{
super("name", 1970); // String,int arguments passed
 //task.
}

This is needed since there is no default no-arg constructor in the base class. You have to explicitly define a no-arg constructor in base class or you need to instruct the compiler to call the custom constructor of the base class.

Note : Compiler will not add default no-arg constructor in a class if it has a user defined constructor. It will add the default no-arg constructor only when there is no constructor defined in the class.


Try this:

Student(String name, int yearOfBirth) {
   super(name, yearOfBirth);
   // task...
}

Reason: you dont have a default constructor at your superclass. So you have to call super() at the first position in your subclass constructor.


Since your super class Person doesn't have a default constructor, in your sub classes (Student and Staff), you must call the super class constructor as the first statement.

You should define your sub class constructors like this:

Student() {
    super("a_string_value", an_int_value);// You have to pass String and int values to super class
}

Staff() {
    super("a_string_value", an_int_value); // You have to pass String and int values to super class
}

the first thing a constructor will do, is call the constructor (with same arguments) of the super class. Person does not have a no-argument constructor, so, you must change your code in one of next two ways:

Student(String name, int yearOfBirth)
{
 //task.
}

or

Student()
{
super("", 0);
 //task.
}

and the same goes for Staff