This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes clone() inherited/overridden(?) in Arrays from Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "clone() inherited/overridden(?) in Arrays from Object" Watch "clone() inherited/overridden(?) in Arrays from Object" New topic
Author

clone() inherited/overridden(?) in Arrays from Object

Ankur Gupta
Ranch Hand

Joined: Jun 13, 2000
Posts: 66

Following is from the JLS
10.7 Array Members
The members of an array type are all of the following:
The public final field length, which contains the number of components of the array (length may be positive or zero)
The public method clone, which overrides the method of the same name in class Object and throws no checked exceptions
All the members inherited from class Object; the only method of Object that is not inherited is its clone method

In the API it specifically mentions that java.util.Arrays inherits all the methods of Object including clone. Nowhere does it mention about the above stmt in the JLS.
Any comments !!?
Ankur
vivek rai
Ranch Hand

Joined: May 08, 2000
Posts: 45
java.util.Arrays is NOT the class which defines the java language arrays. There is no predefined class in the JDK for them, a class is created for an array at the runtime, depending on the type of members ( getClass() for an array of ints would print [I.. its superclass wud be Object )
an arrays class is the same as the following class:
class A implements Cloneable, java.io.Serializable {
public final int length = X;
public Object clone()
{
try
{
return super.clone();
}
catch (CloneNotSupportedException e)
{
throw new InternalError(e.getMessage()); }
}
}
---
so it has to implement clone() method in order to implement the Clonable interface, although it eventually calls Object's clone() .
cheers,
Vivek
Ankur Gupta
Ranch Hand

Joined: Jun 13, 2000
Posts: 66
Vivek,
array and Arrays !! It was confusing I guess. Well! now it is clear. Thanks!
Ankur
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: clone() inherited/overridden(?) in Arrays from Object