Wednesday, March 4, 2009

Puzzle 3 - Solution

The key to solving this puzzle is ' Look at the Object and not the Reference'.

When we create the object of Child any function that we call is first searched in the child class and only then in the base class.

Hence when we execute baseRef.baseCall() the execution happens as follows,

a. First look for the baseCall() in the Child class. Since it is not found look for it in the Base class.
b. Call the function baseCall() in the Base class. This function in turn calls test().
c. Search for test() in the Child class. Since it is found in the Child class, call the function test() in child class

Output of the program is Function Test in Child Executed.

Sorry no correct answers this week!

No comments:

Post a Comment

Solution for this question?