小白求助!

普世干 2014-07-30 05:50:12
代码如下:
class Address
{
String detail ;
public Address(String detail){
this.detail = detail ;
}
}
class User implements Cloneable
{
int age ;
Address address ;
public User(int age){
this.age =age ;
address = new Address("山东莱芜");
}
public User clone()
throws CloneNotsupportedException
{
return (User)super.clone() ;
}
}
public class CloneTest
{
public static void main(String[] args)
throws CloneNotSupportedException{
User u1 = new User(23) ;
User u2 = u1.clone();
System.out.println(u1 == u2) ;
System.out.println(u1.address == u2.address) ;


}
}




在eclipse中出现错误一直不知道如何修改?
运行如下:Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method clone() from the type User refers to the missing type CloneNotsupportedException

at CloneTest.main(CloneTest.java:27)


...全文
247 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
普世干 2014-07-31
  • 打赏
  • 举报
回复
dandan8989251 2014-07-30
  • 打赏
  • 举报
回复
请使用IDE工具。MYECLIPSE,这些代码你肯定是手写一句句一的打上去的。。。。IDE工具会自动检测这种小错误
-江沐风- 2014-07-30
  • 打赏
  • 举报
回复
throws CloneNotsupportedException
修改为
throws CloneNotSupportedException
就是大写;
普世干 2014-07-30
  • 打赏
  • 举报
回复
class Address { String detail ; public Address(String detail){ this.detail = detail ; } } class User implements Cloneable { int age ; Address address ; public User(int age){ this.age =age ; address = new Address("山东莱芜"); } public User clone() throws CloneNotsupportedException 在eclipse中写代码时这行就提示错误,但不知如何修改?在定义这个类?还是引入? { return (User)super.clone() ; } } public class CloneTest { public static void main(String[] args) throws CloneNotSupportedException{ User u1 = new User(23) ; User u2 = u1.clone(); System.out.println(u1 == u2) ; System.out.println(u1.address == u2.address) ; } }

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧