简体   繁体   中英

Does Arrays.toString() override Object's toString() method?

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM