如何解决即使我在Java中有适当的构造函数,为什么我的子类对象始终为空?
我有一个继承自超类的子类,并且我注意到,如果我尝试将其打印出来,则该子类的对象似乎为空。 我以前从未遇到过这样的问题,非常感谢您的帮助。
我有这个子类:
public class OnetimeAppointment extends Appointment {
int year,month,day;
private String description;
public OnetimeAppointment(int year,int month,int day,String description)
{
super();
System.out.println(this.year);
System.out.println(year);
this.year = year;
this.month = month;
this.day = day;
this.description = description;
System.out.println(this.year);
}
public int getYear()
{
return year;
}
public int getMonth()
{
return month;
}
@Override
public boolean occursOn(int year,int day) {
// Todo Auto-generated method stub
return false;
}
@Override
public boolean equals(Object otherObject)
{
return false;
}
}
}
这是超类:
public abstract class Appointment {
private String description;
public Appointment() {
description = "";
}
public abstract boolean equals(Object otherObject);
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
public abstract boolean occursOn(int year,int day);
public String toString() {
return description;
}
public static void main(String args[])
{
Appointment app = new OnetimeAppointment(2020,11,1,"Dentist");
System.out.println(app);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。