Ans: It will compile and give the output "amethod" when run I feel the answer is wronf becauase once a method declared final cannot be used in the subclass..am i right? By the way, can private methods be called in the sub classes?? Sonir
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
1
posted
0
The b.amethod() call is to the method in Base. Even if the code was: Fin f = new Fin(); f.amethod(); It would be to the inherited method from Base. What you can't do is override amethod with a new definition in Fin. Bill [ January 10, 2002: Message edited by: William Brogden ]
The keyword final, when used with a method, simply means that the method cannot be over-ridden. In this case, the method is being inherited, not over-ridden. The following code, however, would be illegal:
However, the following code is perfectly legal because it utilized an inherited method (which can be final).
I hope this makes sense, but the key is that the keyword final means that you can't over-ride a method, not that you can't use it in a child class (that's what the private access modifier is for). Corey
Hi Corey.. I guess both the methods example which u gave are very similar I cannot understand the differnce between the 2. Still u have said that one of them is legal while the other one is not. Can u give me some explainations? Sonir
Jason Kretzer
Ranch Hand
Joined: May 31, 2001
Posts: 280
posted
0
Sonir, Notice that in his second example he did not try to define amethod in the subclass as this is what is illegal. You cannot override(or redefine) a final method that was defined in the super class.
HTH,
Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
Corey McGlone
Ranch Hand
Joined: Dec 20, 2001
Posts: 3271
posted
0
Originally posted by Jason Kretzer: Sonir, Notice that in his second example he did not try to define amethod in the subclass as this is what is illegal. You cannot override(or redefine) a final method that was defined in the super class.
HTH,
Jason is right - it's the declaration of amethod in the subclass that is illegal - not the call to that method. If this is still confusing, please let me know and I'll try to elaborate. Corey