感谢您查看我的帖子以及对我的计划的任何贡献。有人可以帮我调试这个java程序吗。我在main方法中发现了bug,但是没有指出其他方法中的bug。
// A Vaction is 10 days
// but an ExtendedVacation is 30 days
public class testclass1
{
public static void main(String args[])
{
DebugVacation myVacation = new DebugVacation(int days);
DebugExtendedVacation yourVacation = new DebugExtendedVacation(int days);
System.out.println("My vacation is for " +
myVacation.getDays() + " days");
System.out.println("Your vacation is for " +
yourVacation.getDays() + " days");
}
}
//_____________________________________
class DebugExtendedVacation extends DebugVacation
{
public DebugExtendedVacation(int days)
{
super(days);
days = 30;
}
public int getDays()
{
super.getDays();
return days;
}
}
//______________________
class DebugVacation
{
public int days = 10;
public DebugVacation(int days)
{
this.days = days;
}
public int getDays()
{
return days;
}
}
答案 0 :(得分:0)
您的DebugVacation
和DebugExtendedVacation
构造函数需要int
参数。
您必须创建如下对象:
DebugVacation myVacation = new DebugVacation(10);
DebugExtendedVacation yourVacation = new DebugExtendedVacation(10);
这是您的计划必须如何:
// A Vaction is 10 days
// but an ExtendedVacation is 30 days
public class testclass1
{
public static void main(String args[])
{
// Declaration must be done here.
int days = 10; // Or any other value.
// Then you simply pass the value of the variable as a parameter here.
DebugVacation myVacation = new DebugVacation(days);
DebugExtendedVacation yourVacation = new DebugExtendedVacation(days);
System.out.println("My vacation is for " +
myVacation.getDays() + " days");
System.out.println("Your vacation is for " +
yourVacation.getDays() + " days");
}
}
//_____________________________________
class DebugExtendedVacation extends DebugVacation
{
public DebugExtendedVacation(int days)
{
super(days);
days = 30;
}
public int getDays()
{
super.getDays();
return days;
}
}
//______________________
class DebugVacation
{
public int days = 10;
public DebugVacation(int days)
{
this.days = days;
}
public int getDays()
{
return days;
}
}