帮我看个java程序哪错了
来源:百度知道 编辑:UC知道 时间:2024/05/27 14:42:58
import java.util.*;
//import java.lang.Object;
//@author Xu
public class clonetext {
public static void main(String[] args)
{
try{
Text one=new Text("abc",10);
one.type();
Text copy=one.clone();
}
catch(CloneNotSupportedException e)
{
e.printStackTrace();
}
}
}
class Text
{
public Text clone()throws CloneNotSupportedException
{
Text cloned =(Text)super.clone();
cloned.name=(String)super.clone();
cloned.number=(int)super.clone();//编译这行有错!!
}
public Text(String a,int b)
{
name=a;
number=b;
}
public void type()
{
System.out.println(name+number);
}
private String name;
private int number;
}
//import java.lang.Object;
//@author Xu
public class clonetext {
public static void main(String[] args)
{
try{
Text one=new Text("abc",10);
one.type();
Text copy=one.clone();
}
catch(CloneNotSupportedException e)
{
e.printStackTrace();
}
}
}
class Text
{
public Text clone()throws CloneNotSupportedException
{
Text cloned =(Text)super.clone();
cloned.name=(String)super.clone();
cloned.number=(int)super.clone();//编译这行有错!!
}
public Text(String a,int b)
{
name=a;
number=b;
}
public void type()
{
System.out.println(name+number);
}
private String name;
private int number;
}
Test类需要implements Cloneable
public Text clone()throws CloneNotSupportedException
{
Text cloned =(Text)super.clone();
//cloned.name=(String)super.clone();
//cloned.number=(int)super.clone();//编译这行有错!!
return cloned;
}
cloned.number=Integer.parseInt(super.clone());//试试
第二行载入包时前面不要//吧。