File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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
 
Don't get me started about those stupid light bulbs.
 
subject: clone() inherited/overridden(?) in Arrays from Object