Does String class extend Object even though its a final class? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Does String class extend Object even though its a final class?

I'm just trying to figure out the internal workings of valueOf() method because String class has this but it's not overridden 🤔 and slightly confused were the instance is comming from or dosent it matter because either way it's still an instance of String?

16th Mar 2021, 12:27 PM
D_Stark
D_Stark - avatar
2 Answers
+ 3
Object is at the top of the hierarchy and the String class extends it. Final class can extend other classes but it itself cannot be subclassed. The valueOf() in the String class is static so it doesn't allow overriding moreover you need to extend the class first to override a method which is not possible in this case.
16th Mar 2021, 12:37 PM
Avinesh
Avinesh - avatar
+ 2
Avinesh ah yes I knew that i think I'm confusing my self with somthing else thanks for the refresh 😉
16th Mar 2021, 1:00 PM
D_Stark
D_Stark - avatar