Thank you for viewing my post and any contributions to my program. Can someone help me with debugging this java program please. I found the bugs in the main method but cannot point out the bug in the other methods.
// 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;
}
}
Your DebugVacation
and DebugExtendedVacation
constructors require an int
parameter.
You must create objects like this:
DebugVacation myVacation = new DebugVacation(10);
DebugExtendedVacation yourVacation = new DebugExtendedVacation(10);
This is how your program must be:
// 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;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.