JAVA Programming

[54] 객체 복사와 toString 으로 반환값

꾸준히개발하자 2020. 7. 17. 17:18
package object;

class Student2 implements Cloneable  {

	public String name;
	public int num;
	
	public Student2(){
		
	}
	
	public Student2(String name , int num) {
		this.name = name;
		this.num = num;
	}
	
	@Override
	protected Object clone() throws CloneNotSupportedException {
		return super.clone();
	}

	@Override
	public String toString() {

		return name +" 이고  " + num;
	}
}
public class ToStringTest {
	
	public static void main(String[] args) throws CloneNotSupportedException {
		
		Student2 studentkim = new Student2("김철중",100);
		
		Student2 studentLim = (Student2) studentkim.clone();
		
		System.out.println(studentLim.toString());
	}
}