File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overiding methods from String

 
Daniel Martins
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers

Being String a final class, how is it possible to override a method like toString() ?


 
Daniel Martins
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, it just occured to me that if we do not extend String (because we can't), we are basically creating a new method called toString with return type String.

The original one is not visible from within the class...

Am I rigth here...?

Cheers
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It can still be called via "super.toString()", though.
 
Larry Chung
Ranch Hand
Posts: 247
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Martins wrote:Hello Ranchers

Being String a final class, how is it possible to override a method like toString() ?




Daniel, a quick reminder is that the toString() method is inherited by all classes from the Object class not the String class. That toString() method is not final and therefore you can override it till the cows come home.
 
Daniel Martins
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I made a wrong assumption.

Thank you!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic