0

I am learning how to make a superclass. I have been successful setting it all up I just need help learning how to call a default constructor.

Here is what I have Superclass file:

public class Date {

private int month;
private int day;
private int year;

Date() {

}

Date(int passedMonth, int passedDay, int passedYear){
   month = passedMonth;
   day = passedDay;
   year = passedYear;
}

SubClass:

public class GregorianDate extends Date {
//*************** Constructors ***********************
GregorianDate() {
    long numToAdd = System.currentTimeMillis();
    numToAdd += java.util.TimeZone.getDefault().getRawOffset();
    numToAdd /= 86400000;
    super.addDays(numToAdd);
}
//Parameterized constructor
GregorianDate(int passedYear, int passedMonth, int passedDay){
    super(passedMonth, passedDay, passedYear);
}

What I need to do is call the default constructor in the sub class to update the correct default constructor to today's date. somehow in the superclass to assign the month, day, and year values.

user9501082
  • 45
  • 1
  • 6

1 Answers1

0

The super class should have its own initialisers in the constructors that you can selectively override in the sub class constructors.

Which is not possible unless you have the super class in code.

Hope this addresses your doubt.

Vasu Inukollu
  • 120
  • 1
  • 3
  • 10