File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes simple........ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "simple........" Watch "simple........" New topic
Author

simple........

M Karthikeyan
Greenhorn

Joined: Sep 20, 2000
Posts: 2
abstract class ab
{
abstract void add();
abstract void sub();
}
class ba extends ab
{
void add()
{
System.out.println("Addition");
}
void sub()
{
System.out.println("Subtraction");
}

}
class abs
{
public static void main(String[] args)
{
System.out.println("Hello World!");
ba a1= new ba();
ba a2=(ba)a1.clone();
}
}
this code gives the following error:-
abs.java:24: Can't access protected method clone in class java.lang.Object. ba is not a
subclass of the current class.
ba a2=(ba)a1.clone();
Anyone help me out. Thanx in advance.


Karth
Serge Plourde
Ranch Hand

Joined: Jun 23, 2000
Posts: 140
Hi Karthikeyan,
You are getting this message because your class is not overriding the method clone of the class Object.
If you want your class to have cloneability, you must override clone in your class and declare it public. Also your class must implement the Cloneable interface.
In your clone method you must first call super.clone().
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Notes from the documentation on Object about clone()
The method clone for class Object performs a specific cloning operation. First, if the class of this object does not implement the interface Cloneable, then a CloneNotSupportedException is thrown.
The class Object does not itself implement the interface Cloneable, so calling the clone method on an object whose class is Object will result in throwing an exception at run time. The clone method is implemented by the class Object as a convenient, general utility for subclasses that implement the interface Cloneable, possibly also overriding the clone method, in which case the overriding definition can refer to this utility definition by the call:
super.clone()
The code then becomes something like :

Hope this helps


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
M Karthikeyan
Greenhorn

Joined: Sep 20, 2000
Posts: 2
Thanx guys!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: simple........