0

I am making an object class inherited from my base class. I am trying to make my default non argument constructor using this(), and it keeps highlighting red when I try to make a default Date object cuz of my Date instance variable.

PS (I already tried instantiating inside the new Date() brackets with the instance variables in Date class) Any ideas why or how to fix?

public class Employee extends Person
{
    private Date hireDate;

    public Employee()
    {
        this("No name", new Date() ); //THIS IS RED
    }
}
5
  • 3
    Did you mean super(...) instead of this(...)? Constructors aren't inherited. Commented Sep 16, 2022 at 1:29
  • I am not sure because my professor used this as an example, he only uses super with the argument constructor Commented Sep 16, 2022 at 1:34
  • public class HourlyEmployee extends Employee{ private double wageRate; private double hours; public HourlyEmployee() { this("No name",new Date(),0.0,0.0); } public HourlyEmployee(String name, Date hireDate, double wageRate, double hours) { super(name, hireDate); setWageRate(wageRate); setHours(hours); } Commented Sep 16, 2022 at 1:34
  • 1
    //THIS IS RED aside marking part of code as red, editor also generates text with information about reason behind it. Try to look for it. Commented Sep 16, 2022 at 1:40
  • 1
    Your code is wrong. There is no constructor for an Employee that accepts a String and a Date; therefore you cannot call it. If your professor wrote something like it, he's wrong too. Commented Sep 16, 2022 at 1:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.