File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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: 41146
    
  45
It can still be called via "super.toString()", though.


Ping & DNS - my free Android networking tools app
Larry Chung
Ranch Hand

Joined: Feb 02, 2010
Posts: 247
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Overiding methods from String
 
Similar Threads
ArrayList Sorting Using Comparator? Exception at Runtime
Help getting back on track with assignment
Which Access Modifier when override toString()?
Override toString() when you want a mere mortal to be able to read something meanningful about the..
toString