Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String related  RSS feed

 
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?
 
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!