청춘만화 2012. 2. 23. 00:14





class TestAA
{
int i;
TestAA(int a){
i = a;
}
public String toString(){
return "i 맴버 변수의 값은 : " + i + "이다."; //this.i=i
}
}

public class Num03 {
public static void main(String[] args) {
TestAA t1 = new TestAA(10);
TestAA t2 = new TestAA(20);
System.out.println(t1);
System.out.println(t2);
}
}











class Test1 implements Cloneable {
int a,b;
Test1(int a, int b){
this.a = a;
this.b = b;
}
public String toString(){          //타입일치:String
return ("a=" + a + " " + "b=" + b);
}
public Test1 boksa(){
Object obj = null;
try {
obj = clone();       //this.clone()
} catch(CloneNotSupportedException e){}  
           //Exception는 try catch 블럭을 통해서만 호출 가능하다.
                                                   // (예외처리 위해만든 함수!)
return (Test1)obj; //cast
}
}

public class Num04 {
public static void main(String[] args) {
Test1 t = new Test1(10,20);
Test1 b = t.boksa();
System.out.println(t);
System.out.println(b);

System.out.println(t.toString());    //=
System.out.println(b.toString());    //=
}