📄 example10_16.java
字号:
import java.io.*;
class GetCloneObject
{ public Object getClone(Object a)
{Object object=null;
try{
ByteArrayOutputStream outOne=new ByteArrayOutputStream();
ObjectOutputStream outTwo=new ObjectOutputStream(outOne);
outTwo.writeObject(a);
ByteArrayInputStream inOne=new ByteArrayInputStream(outOne.toByteArray());
ObjectInputStream inTwo=new ObjectInputStream(inOne);
object=inTwo.readObject();
}
catch(Exception event){System.out.println(event);}
return object;
}
}
class Student implements Serializable//实现接口Serializable的Student类。
{ double height;String number;
Student(String number,double height)
{ this.number=number;this.height=height;
}
public void setHeight (double c)
{ this.height=c;
}
public void setNumber (String number)
{ this.number=number;
}
}
class School
{
public void setStudent(Student s, String number,double m)
{
s.setNumber(number);
s.setHeight(m);
}
}
public class Example10_16
{ public static void main(String args[])
{
try{
GetCloneObject cloneObject=new GetCloneObject();
School school=new School();
Student student=new Student("0000000",0.0);
Student studentClone=(Student)cloneObject.getClone(student);
school.setStudent(studentClone,"2006001",1.78);
System.out.println(student.number+"身高"+student.height);
System.out.println(studentClone.number+"身高"+studentClone.height);
}
catch(Exception e){}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -