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
posted
0
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...
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.