Looking at the String class declaration , you can see that it extends Object class.
public final class String
extends Object
implements Serializable, Comparable<String>, CharSequence
What is the point of explicitly writing extends Object where it actually isn't required ?
is their any logical reason behind this ?
It doesn't in the official oracle JDK source code. Which version are you looking at?
public final class String
    implements java.io.Serializable, Comparable<String>, CharSequence
Either way, it wouldn't make a difference whether you wrote extends Object or not in the source code. Beware though, if you had to extend another legitimate class instead of Object, you'll hit a dead end as Java doesn't support multiple inheritence.
The OP is looking at the declaration of String in the API documentation. Every class in Java must and do extend Object. However, it is a different thing whether the source code says extends Object.
The String class doesn't have extends Object in the source code. However, the API declaration always indicates that every class extends Object implicitly.
Have a look at the source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With