I have 1 subclass and 1 superclass with which i am learning design
patterns
Anyhow the snag ive run into is this
I have a variable of the same name in my super and sub classes
When I declare it like this
String PizzaType="Cheese"; in my subclass the compiler
complains saying that I am hiding fields.
So I think of course you already know about the variable because it's declared in the superclass so I
will just like to change the value please Mr compiler so I put down PizzaType="Cheese"; without declaring it
And the compiler complains that it cant find symbol "PizzaType".
I even try super.PizzaType="Cheese";
I can't win! Ok I have just discovered that everything works well when you use the constructor to change the value
for example
public class PeperoniPizza extends Pizza
{
public PeperoniPizza()
{ PizzaType=" Peperoni"; }
}
But I would still like to know why what I was trying wouldn't work until I used the constructor
Thanks for help