Hi All, I have some doubts regarding the below mentioned question.
The answer of above question is given as, it will print: Parent's method2() Parent's method1() In the explanation, given that if we change the access modifier for method1() in Parent class as Public, it will print: Parent's method2() Child's method1()
I have tested the code with both mentioned scenario, and it is giving desire output.
Please help me in understanding both above mentioned scenario.
Hi Manoj, Private methods are not inherited.So in Child class method1() is not overriden.Its a new method introduced. But, when you declare Parent classe's method1() as public , you are overriding the same method in the Child class. During runtime the subclass version of the method1() runs. I think i made it clear to you.
SCJP 6 (80%) || SCWCD 5 (92%)
So I left, I came home, and I ate some pie. And then I read this tiny ad: