<p>Can anyone help me on inheritance? I don't really understand how it works. For example in 5 steps to a 5, page 107 problem 8.</p>
<p>Pet a = new Pet();
Feline b = new Feline();
Pet c = b;
a.animal();
b.animal();
c.animal();</p>
<p>I don't understand what method c.animal() would call. Would it call the Pet animal() method or the Feline() method, and what determines this?</p>
<p>Hi killernago,</p>
<p>If the animal() method is defined in Feline as well as Pet, then the Feline method will be called in the example you have. This happens because you are using the Feline class to extend Pet object. This works in the same way for the Pet class; in your example, you defined a as a Pet and created it with the Pet class "Pet a = new Pet();". Since a was created by the Pet class, a.animal() calls the animal method in the Pet class, not the Feline class.</p>
<p>This:
Pet a = new Feline();
a.animal();</p>
<p>results in calling the animal() method defined in the Feline class because it was created by the Feline class.</p>
<p>I hope that cleared things up a little for you.</p>