aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overiding methods from String Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Overiding methods from String" Watch "Overiding methods from String" New topic
Author

Overiding methods from String

Daniel Martins
Ranch Hand

Joined: Oct 22, 2009
Posts: 45
Hello Ranchers

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


Daniel Martins
Ranch Hand

Joined: Oct 22, 2009
Posts: 45
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
Marshal

Joined: Mar 22, 2005
Posts: 35437
    
    9
It can still be called via "super.toString()", though.


Android appsImageJ pluginsJava web charts
Larry Chung
Ranch Hand

Joined: Feb 02, 2010
Posts: 245
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.


SCJP 6
Daniel Martins
Ranch Hand

Joined: Oct 22, 2009
Posts: 45
Ok, I made a wrong assumption.

Thank you!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overiding methods from String
 
Similar Threads
Override toString() when you want a mere mortal to be able to read something meanningful about the..
Which Access Modifier when override toString()?
Help getting back on track with assignment
toString
ArrayList Sorting Using Comparator? Exception at Runtime