생성할때
1. 인스턴스 변수 초기화
2. 주소반환
기본생성자
클래스 이름 () {}
** 기본적으로 주소 return **
package chapter05;
public class Cellphone {
String model = "Galaxy 8";
String color;
int capacity;
Cellphone (String color, int capacity) { // 매개변수가 있는 생성자
this.color = color;
this.capacity = capacity;
}
}
package chapter05;
public class exam39 {
public static void main(String[] args) {
Cellphone myphone = new Cellphone("Silver", 64); // 생성자 호출
System.out.println(myphone.model);
System.out.println(myphone.color);
System.out.println(myphone.capacity);
}
}