This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
By default, the method without any modifier has a default access which means it is accesible in that particular package by any class defined in the same package. So your answer of marking the method public is not the one I expected. I came across this question from a website,
# Assume that class A extends class B, which extends class C. Also all the three classes implement the method test(). How can a method in a class A invoke the test() method defined in class C (without creating a new instance of class C). Select the one correct answer.
1. test(); 2. super.test(); 3. super.super.test(); 4. ::test(); 5. C.test(); 6. It is not possible to invoke test() method defined in C from a method in A.
The answer given was 6. But I feel it is 1. By the way what "Also all the three classes implement the method test()" means from the question above?Did they mean Overriding??
I tried it using the code as below,
and I got the o/p, I'm from the top class. So answer option 1 is correct in the above mentioned question. Anyone corrections on this?
Regards, Jothi Shankar Kumar. S [ October 27, 2006: Message edited by: Jothi Shankar Kumar Sankararaj ]
but the question asks you "How to call a method in C from the Class A"
this is not possible because you can only refer to you're immediate superclass
if you want to go further up in the hierarchy then you need to go to Class B and change the code..
run the above code...
and try calling the test() of the Class C if you can with the given options.. you cant... if you want to then call class B's test method by calling super.test() and then from class b's test method call class c's test() method by saying super.test() again
If I comment the test() method in class B, then the call super.test() in Main class will check for the method first in B, if the method is not available, it will check in it's superclass which is A. Ok I understand it now.