hahahia

[Java] 생성자 예제 본문

Language/Java

[Java] 생성자 예제

hahahia 2012. 10. 13. 17:37

Java 생성자 예제



/**
 * Created with IntelliJ IDEA.
 * User: hahahia
 * Date: 12. 10. 13
 * Time: 오후 5:25
 * To change this template use File | Settings | File Templates.
 */
public class TopConstructor {
    private String name = null;
    private String address = null;
    private int age = 0;

    public TopConstructor(){
        name = "이름 없음" ;
        address = "주소 없음" ;
        age = 0;
    }
    public void setData(String n, String a, int g){
        name = n;
        address = a;
        age = g;
    }
    public String getData(){
        String str = name + ", " + address + ", " + age;
        return str;
    }
    public static void main(String[] args){
        TopConstructor tc = new TopConstructor();
        String s;
        s = tc.getData();
        System.out.println(s);
        tc.setData("Minhwa", "Incheon", 25);
        s = tc.getData();
        System.out.println(s);
    }
}


제대로 자바를 공부해보는게 처음이라...ㅎㅎ
Comments