Sunday, April 26, 2009

Puzzle 18 – Solution

Puzzle 18 was a bit of a trick question. The key to the puzzle is 'Dynamic polymorphism comes into play only at run time. At compile time its the reference that matters!'

Output – Compilation Error at line number 16 - base.test()

Reason – The compiler identifies base.test() as a Base class method which throws an exception that has not been handled in the main method. (The compiler does not know or care what object the reference base will point to at run time).

Congrats to
1. Bernardomen
for getting the reason spot on!

No comments:

Post a Comment

Solution for this question?