• Post Reply Bookmark Topic Watch Topic
  • New Topic

String related  RSS feed

 
Pankaj Mittal
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If String class is final then how can we override its equals method?
 
Raphael Rabadan
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pankaj Mittal:
If String class is final then how can we override its equals method?


equals method comes from Object, not from String.

You cant even extends String to try to override it.

We can override the equals methods because all classes inherits it from Object.

The only way you can't override equals is when a child extends a parent that defined it as final.

See this example:


Kind Regards,
Raphael Rabadan

[ July 18, 2008: Message edited by: Raphael Rabadan ]
[ July 18, 2008: Message edited by: Raphael Rabadan ]
 
Pankaj Mittal
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!