Ans :
In the Main First two lines will call the ChildClass constructor. But it will invoke the BaseClass constructor before executing the method block. The First 2 lines of the answer are a result of the execution of the first line in the main. Simultaneously 3rd and 4th lines of the answer are the result of the 2nd line in main.
Which MethodTest will be executed?
It depends on the reference we have. The 'baseClass' object has a reference to BaseClass and hence MethodTest of BaseClass will be executed. The 'childClass' object has a reference to ChildClass and hence MethodTest of ChildClass will be executed.
No comments:
Post a Comment