Accessing Private Int in a Subclass
Superclass source code
public class Date {
private int month;
private int day;
private int year;
public Date() {
setMonth(1);
**day = 1;**
setYear(1900);
}
public Date(int month, int day, int year) {
this.setMonth(month);
this.**day** = day;
this.setYear(year);
}
Month and Year works fine because I can use the setMonth and setYear in my subclass. However, when I try to use day it says the var is not visible because its private. There is no setter for day in the superclass but there is a getter. What should the setter look like? Furthermore, what should my subclass contructor look like?
Subclass contructor
public EDate(int month, int day, int year)
{
this.setMonth(month);
day = getDay();
this.setYear(year);
}
Subclass Day setter
public void setDay(int newInt) {
if (isGooddDate(getMonth(), newInt, getYear())==true)
{
newInt = this.getDay();
}
Any help is much appreciated!
Re: Accessing Private Int in a Subclass
Please post the full code and the full text of the error message you are getting.
Be sure to wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting