On Sep 6, 12:25 pm, Norman Ho <[EMAIL PROTECTED]> wrote:
> I am a bit confused on the difference between Inheritance and Run time
> Polymorphism.
> Take the example of:
>
> Person person3 = new InternationalStudent();
> person3.myMethod("test5");
>
> and,
>
> InternationalStudent person4 = new InternationalStudent();
> person4.myMethod("test7");
>
> petrson3 is of type Person, but an instance object of
> InternationalStudent, so it can reference all the fields and methods
> of Persons and InternationalStudent, any method of the same name in
> the superclass are overridden by that of the subclass.
>
> person4 is of type InternationalStudent and an object instance of
> InternationalStudent, so it can reference all the field and methods of
> InternationalStudent and all that of the super class. (Student,
> Person, Object),
> any method of the same name in the super class are overridden class.
>
> person3 and person4 seems to go through exactly the same processes, I
> am sure there is a subtle difference, but I can’t quite work it out
The difference resides in the fact that one object type is known at
compile time, the other one will be known as runtime time.
For more in depth details about how it affects the choice of methods
accessible, see Thinking in Java, two chapters, the one on Inheritance
and the one on Polymorphism. Hard to read, quite long, but some
drawing explain this.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---