Given:
3. class Animal { 4. String name = "furry "; 5. String talk() { return "generic noise"; } 6. } /*from w w w . j a v a 2 s . c om*/ 7. class Dog extends Animal { 8. String name = "stripes "; 9. String talk() { return "bray"; } 10. } 11. public class Main { 12. public static void main(String[] args) { new Main().go(); } 13. void go() { 14. Animal m = new Dog(); 15. System.out.println(m.name + m.talk()); 16. } 17. }
What is the result?
A is correct.
Polymorphism is only for instance methods, not instance variables.