[필드-1] User

seratpfk·2022년 7월 27일
0

JAVA

목록 보기
40/96

User (메인메소드 없음)

String id;         // null
String password;   // null
String email;      // null
int point;         // 0
boolean isVip;     // false

User를 구성하는 속성(Attribute)이 필드(Field)이다.
필드는 일반 변수와 달리 자동으로 초기화된다.

객체 선언

User user = null;

객체 생성

user = new User();

객체 선언과 생성을 한 번에

User user = new User();

UserMain (메인메소드 설정)

User user = new User();
user.id = "admin";
user.password = "123456";
user.email = "admin@web.com";
user.point = 1000;
user.isVip = (user.point >= 10000);
System.out.println(user.id);
System.out.println(user.password);
System.out.println(user.email);
System.out.println(user.point);
System.out.println(user.isVip);

동일 패키지는 임폴트없이 이름만으로도 사용가능

모든 User 객체는 필드값을 가지고 있다.
마침표(.)를 이용해서 필드값을 호출한다.

0개의 댓글