Reputation: 5762
Hello everyone this is making me confuse...
All the toString() methods in Arrays
class are static, so does this really override Object
's toString() method? Someone told me that:
No, it doesn't override Object's toString method. It contains the inherited toString from Object, which is never used since one cannot instantiate the class. What you see in Arrays class, is overloaded versions of toString.
So I went to the source code but didn't see such thing. Am I missing some thing? sorry for asking such a noob question.
Upvotes: 1
Views: 920
Reputation: 234797
Object
's toString()
method has no arguments. All the toString
methods in Arrays
have arguments of one sort or another, so they don't override the toString()
method inherited from Object
. They are distinct methods that have no relationship (as far as the compiler is concerned) with Object.toString()
. To use the inherited toString()
instance method, though, you would need an instance of Arrays
to invoke the inherited method, and since you cannot have one of those, it is of no consequence.
Upvotes: 0
Reputation: 382150
The Arrays
class is a utility class. As it isn't instantiable, Object's toString
method is irrelevant.
The static toString
methods you see are totally unrelated to the standard toString
method, as should be clear from their description in the javadoc. Note also the plural form : there's more than one method with this name and none of them has the same signature as the Object's one : they all take some argument.
Upvotes: 7