본문 바로가기

Java

Day5 - 03

public class Student {
    private int no;
    private String name;
    private String hp;
    private String address;
    private String blood;
    private String mbti;

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getHp() {
        return hp;
    }

    public void setHp(String hp) {
        this.hp = hp;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getBlood() {
        return blood;
    }

    public void setBlood(String blood) {
        this.blood = blood;
    }

    public String getMbti() {
        return mbti;
    }

    public void setMbti(String mbti) {
        this.mbti = mbti;
    }

    public void info(){
        System.out.println("[학번:"+no+", 이름:"+name+", 전화번호:"+
                hp+", 주소:"+address+", 혈액형:"+blood+", MBTI:"+mbti+"]");
    }
}
public class Oop2 {
    public static void main(String[] args) {
        Student student1 = new Student();
        Student student2 = new Student();       // 새로운 객체공간을 만들고 불러올 수 있는 변수 student2
        student1.setNo(2);
        student1.setName("김사과");            //getter setter 사용한후 객체 변수이름.SetName()에 직접 값을 입력한다
        student1.setHp("010-1111-1111");
        student1.setAddress("서울 서초구 양재동");
        student2.setAddress("경기도 부천시 소사구 소사본동");    //student2에 주소값만 써주고 나머지 값을 안써주면 디폴트값으로 설정됨
        student1.setBlood("A형");
        student1.setMbti("INFJ");
        System.out.println(student1.getHp());       //println은 객체주소를 참조하는 변수.get변수();--> 맞는 변수에 내가 써놓은 값을 출력해준다
        System.out.println(student1.getAddress());
        student1.info();
        student2.info();
    }
}

'Java' 카테고리의 다른 글

Day06  (0) 2023.02.01
Day05 - 4  (0) 2023.02.01
Day5 - 01(Method)  (0) 2023.01.29
Day5  (0) 2023.01.29
Day4 - String 클래스! 타입x  (0) 2023.01.27