728x90
반응형
class Updater {
void update(Counter counter) {
counter.count++;
}
}
class Counter {
int count = 0; // 객체 변수
}
public class Main {
public static void main(String[] args) {
Counter myCounter = new Counter();
System.out.println("before update:"+myCounter.count);
Updater myUpdater = new Updater();
myUpdater.update(myCounter);
System.out.println("after update:"+myCounter.count);
}
}

728x90
반응형
'즐거운프로그래밍' 카테고리의 다른 글
[자바] 인터페이스(interface) (0) | 2023.11.13 |
---|---|
[자바] 상속(inheritance) (0) | 2023.11.13 |
[자바] 자바 클래스(class)의 이해 (0) | 2023.11.13 |
[자바] 자바 객체 지향 프로그래밍(계산기 예제) (0) | 2023.11.13 |
[자바] 예제 3 : 도서 목록 필터링 및 리스트화 하기 (0) | 2023.11.09 |