HI,
I am not able to get this code: Chapter 2 K&B exercise problem 13
class Mammal
{
String name = "Hello";
String make()
{
return "A";
}
}
class zef extends Mammal
{
String name = "HHH";
String make()
{
return "S";
}
}
public class Zoo
{
public static void main(String args[])
{
new Zoo().go();
}
void go()
{
Mammal m = new zef();
System.out.println(m.name+m.make());
}
}
Output: HelloS
I know m is an object of class zef referencing to class Mammal.
So m.name will display the instance variable of class Mammal.
But what about the method make ?
Why the instance method looks the subclass.
Can anyone explain this ?
Thank you.
Dimple.