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
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
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.
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>
Joined: Dec 20, 2001
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.
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