Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding final methods

 
Sagar Salapaka
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sagar Salapaka
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Thiru. It makes sense. Learnt something new today. Have a nice day!
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, private methods are implicitly final, so including the final modifier is redundant.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic