public class InheritanceExample { static public void main(String[] args){ Cat c = new Cat(); System.out.println(c.speak());
You're hiding fields. The sound in Animal is not the same String as the sound in Cat.
sound
Animal
String
Cat
One possible solution is to create a constructor and there simply say
super.sound = "meow";
instead of in the class body saying
protected String sound = "meow";
to set the field.