But you aren't accessing message via a Child reference. You're calling say() on a Child reference. That executes the code in Parent (because the method is not overridden in Child), and that's where you access message.
Before subclass object getting instantiated the super class constructor gets called and its object gets instatiated. As say() method is not being overridden there super class say() mehod is being called and there it is using message field of its own. If you override the say() method in the subclass then it will be called.
fact 1: Child class have inherited the say() from parent. True
fact 2: To call the method of a class one must use object of that class. True
fact 3: Child object is created and inherited say() is called . True
fact 4: say() of Parent is called . Why?
Joined: Oct 19, 2011
say() of Parent class is called as say() is not overloaded in Child.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com