class Mammal {
String name = "furry";
String makeNoise() { return "generic noise";}
}
class Zebra extends Mammal {
String name = "stripes";
String makeNoise() { return "bray";}
}
public class Zoo {
public static void main (String[] args) { new Zoo().go();}
void go() {
Mammal m = new Zebra();
System.out.println(m.name + m.makeNoise());
}
}
output: furry bray
My doubt is that why isn't the output stripes bray? I understood the bray part as subclass method gets invoked during runtime. but m.name behavior i did not get? Help pl. Thanks in advance.