File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overriding final methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriding final methods" Watch "Overriding final methods" New topic
Author

Overriding final methods

Sagar Salapaka
Greenhorn

Joined: Feb 06, 2002
Posts: 12
I thought final methods cannot be overridden. But the below code compiles just fine. Can somebody explain.

[ Added UBB [CODE] tags to add whitespace, improve readability ]
[ May 14, 2002: Message edited by: Jessica Sant ]
[ May 14, 2002: Message edited by: Sagar Salapaka ]
Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
I think the f() method in WF is private which is accisible within only WF class. If you declare the f() in WF to be public or protected, you will get compile time error what you are expecting. The f() method declared in derived class is consided a brand new method which is no connection with the superclass. Guys, am i correct?


Thanks,<br />Thiru<br />[SCJP,SCWCD,SCBCD]
Sagar Salapaka
Greenhorn

Joined: Feb 06, 2002
Posts: 12
Thanks a lot Thiru. It makes sense. Learnt something new today. Have a nice day!
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by Thiru Thangavelu:
I think the f() method in WF is private which is accisible within only WF class...Guys, am i correct?

Yup, that's right. Private methods are not inherited. In fact, they're not even visible from outside the class, so you can't possible override or hide them.
Corey


SCJP Tipline, etc.
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Also, private methods are implicitly final, so including the final modifier is redundant.


Rob
SCJP 1.4
 
Don't get me started about those stupid light bulbs.
 
subject: Overriding final methods