В нижней части подкласса мне нужны 3 строки из моего суперкласса для печати с помощью оператора switch. Он не будет печатать System.out.println(super.display());
, потому что это, очевидно, void
.Попытка печати в подклассе из суперкласса
Я не могу понять, как это сделать.
супер класс:
public void display()
{
String fullLocation = "";
switch (location)
{
case 'N': case 'n': fullLocation = "North London";
break;
case 'S': case 's': fullLocation = "South London";
break;
case 'E': case 'e': fullLocation = "East London";
break;
case 'W': case 'w': fullLocation = "West London";
break;
default: fullLocation = "Central London";
break;
}
System.out.println("The address of this property is at " + address + ".");
System.out.println("This property is in " + fullLocation);
System.out.println("This property has " + bedrooms + " bedrooms");
}
Суб класс:
public void display()
{
String buyer = purchaser;
if(sold == true){
*System.out.print(super); ???*
System.out.println("The price of this property is £" + price + ".");
System.out.println("The owner of this property is " + purchaser + ".");
}
else{
System.out.println("The startic price for this property is £" + price + ".");
System.out.println("The property is still on the Market");
}
}
спасибо очень много. –