헤드 퍼스트 자바를 공부하면서 푼 문제들 정리
기본값
연필을 깍으며
public class TestBox {
Integer i;
int j;
public static void main(String[] args) {
TestBox t = new TestBox();
t.go();
}
public void go() {
j = i;
System.out.println(j);
System.out.println(i);
}
}
정답 객체의 레퍼런스인 i의 초기값이 null이기 때문에 'j = i'에서 예외 발생함.