myTest라는 객체를 이용하여 vartest라는 메소드를 호출할 경우 굳이 myTest라는 객체를 전달할 필요가 없다. 왜냐하면 전달하지 않더라도 vartest 메소드는 this라는 키워드를 이용하여 객체에 접근할 수 있기 때문이다. this를 이용하여 vartest메소드를 수정한 버전은 다음과 같다.
public class Test {
int a; // 객체변수 a
public void vartest() {
this.a++;
}
public static void main(String[] args) {
Test myTest = new Test();
myTest.a = 1;
myTest.vartest();
System.out.println(myTest.a);
}
}
status | not read | reprioritisations | ||
---|---|---|---|---|
last reprioritisation on | suggested re-reading day | |||
started reading on | finished reading on |