【发布时间】:2019-03-15 06:31:32
【问题描述】:
public class Date {
private int day;
private int month;
private int year;
public Date(int theDay, int theMonth, int theYear) {
}
public void setDay(int theDay) {
day = theDay;
}
public int getDay() {
return day;
}
public void setMonth(int theMonth) {
month = theMonth;
}
public int getMonth() {
return month;
}
public void setYear(int theYear) {
year = theYear;
}
public int getYear() {
return year;
}
public void displayDate() {
System.out.printf("The current date is: %d/%d/%d", getDay(), getMonth(), getYear() );
}
}
+
public class DateTest {
public static void main( String[] args ) {
Date myDate = new Date(20, 5, 2010);
myDate.displayDate();
}
}
结果:当前日期为:0/0/0 预期结果:20/5/2010
我检查了很多次,我看不出任何错误。确保记录更改并重新启动 Eclipse。你怎么看 ?这是我在这里的第一篇文章,如果这里的发帖形式不正确,很抱歉。 谢谢!
【问题讨论】:
-
提示:查看构造函数的主体。你在用参数做什么?您希望这些字段如何获取值?
-
术语点:methods和constructors有论据;对象没有。
标签: java default-value instance-variables