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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
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: 39549
    
  27
It can still be called via "super.toString()", though.


Ping & DNS - updated with new look and Ping home screen widget
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!
 
wood burning stoves
 
subject: Overiding methods from String
 
Similar Threads
toString
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..
ArrayList Sorting Using Comparator? Exception at Runtime