Everything here is renamed and simplified.
I have a parent class (normalThing) with a method that displays some data about the instance, and another class (specialThing) extending the parent to include another instance variable (addedPrice).
I want my display method to say whether or not the instance is a specialThing, and if it is, to display the addedPrice. But because addedPrice belongs only to specialThing, I can't figure out how to code it!
void displayInfo(){
StringBuilder d = new StringBuilder("Am I special? ");
if(this instanceof specialThing){
d.append("Yes, so I cost an extra " + this.addedPrice);
//No, I didn't expect that to work, but I had hope
}
else d.append("Nope.");
JOptionPane.showMessageDialog(null, d);
}
Is there any way to do this without essentially making a "could-be-addedPrice" variable in the normalThing class?