[Java] 기본형vs참조형 / null 퀴즈
·
TIL/Java
출력되는 값은 무엇입니까? 0 int[] a = new int[2]; System.out.println(a[0]); 출력되는 값은 무엇입니까? null Person[] people = new Person[2]; System.out.println(people[0]); 출력되는 값은 무엇입니까? 0 Person person = new Person(); people[0] = person; person.age = a[0]; a[0] = 26; System.out.println(person.age); 출력되는 값은 무엇입니까? 27 a[0]++; people[1] = people[0]; people[1].age = a[0]; a[0] = 28; System.out.println(people[0].age); 출력되..
[Java] 기본형 vs 참조형
·
TIL/Java
기본형(Primitive Type) : 변수가 값 자체를 보관 int, boolean, char, double 등 참조형(Reference Type) : 변수는 값이 보관되어 있는 영역을 가리킴(실제 값은 메모리 어딘가에 저장되어있고 변수는 그 메모리를 가리키는 역할) Person, String, int[] 등 클래스 기반 자료형(배열을 포함한 객체 모두) 기본형 (Primitive Type) 기본형의 경우에는 변수가 값 자체를 보관 int a = 3; int b = a; System.out.println(a); // 3 출력 System.out.println(b); // 3 출력 a = 4; System.out.println(a); // 4 출력 System.out.println(b); // 3 출력 ..