Calling the inherited test method through child object is same as calling the original test method from parent object.
Regards,<br />Vijaya Bharath.<br />SCJP1.4 <br />SCWCD5.0
Output :
Mom : Test Mom
Mom : Test Mom
Mom : Test Mom
when you call test method through child object it calls the parent method only
Mom : Test Mom calling from class: Mom
Mom : Test Mom calling from class: Child
Mom : Test Mom calling from class: Child
Mom : Test Mom calling from class: Mom
Child : Test Mom calling from class: Child
Child : Test Mom calling from class: Child
Mom : Test Mom calling from class: Mom // Line 1
Mom : Test Mom calling from class: Child // Line 2
Mom : Test Mom calling from class: Child // Line 3
Shouldn't this.s refer to the currently executing object's variable s?
In first line, we are refering to Mom object. But in second and third line, we are refering to Child object.
all events occur in real time
Originally posted by Yogesh Baraskar:
1. If method is overridden by a sub-class and subclass has the same variable name as declared in Super class, then any call (whether it is on subclass reference or super class reference ) to that method will display the value of variable declared in subclass.
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
|