This(2)
-
[Java] 2020.11.04. day_11 기본형데이터형, 참조형데이터형, this, String class, String class method
◎ this this method형식 추후에 배울 예정 this(); 기본생성자를 호출 this(값); 매개변수 있는 생성자를 호출 직접호출불가 new를 사용해서만 호출가능(객체화를 할 때만 호출된다) 자신클래스의 다른 생성자를 호출할 때 사용 생성자의 첫 번째 줄에서만 사용가능 재귀호출에 상황이 발생하면 error keyword형식 this.변수명 this.method명(); this는 생선된 객체의 주소를 가지고 있는 키워드다 (Test t=new Test(); t를 this로 바꿔서 사용할 수 있다) 생성된 객체의 instance 변수나 instance method를 호출할 때 사용 instance 영역에서만 사용가능 (객체명. method() ) static영역에서는 사용불가 (static 영역은..
2020.11.04 -
[Java] 2020.11.03. day_10 getter,setter,생성자,추상화하여 클래스 만들기
◎ getter, setter method ○ getter method getter method 특징 class 의 instance 변수가 private으로 설정 되어있을 때, instance 변수의 값을 클래스 외부에서 받아가기 위해서 만드는 method get을 접두어로 사용하고 변수명을 붙여서 만들어준다 get변수명 형식을 가진다 규칙 public 반환형 get변수명( ){ return 변수명; } 예 class Test{ private int age; public int getAge(){ return age; } } ○ setter method setter method 특징 클래스 instance 변수의 값을 변경하기 위한 method instance 변수는 외부에서 값을 직접 변경하지 못하도록 ..
2020.11.03