(접근 제어자) class 클래스 이름 {
멤버 변수;
메서드;
}
-> 학생 클래스 만들기
-> 학생 이름과 주소 출력하는 메서드 만들기
package domain.student.view;
public class StudentView {
}
-> 클래스 이름: StudentView
-> 클래스의 전체 이름(class full name): domain.student.view.StudentView
int add (int num1, int num2) { // int = 함수 반환형 / add = 함수 이름 / (int num1, int num2) = 매개변수
int result;
result = num1 + num2;
return result; // return = return 예약어
Student studentAhn = new Student();
-> 여기서 studentAhn를 참조변수라고 하고, 이 변수가 생성된 인스턴스를 가리킨다.
-> 클래스는 하나지만 이 클래스로부터 여러 개의 각각 다른 인스턴스를 생성할 수 있다. 어떤 학교에서 학생이란 추상어는 뜻이 하나지만, 그 학교에 다니는 학생 개개인은 여러 명인 것과 마찬가지다.
참조 변수.멤버 변수
참조 변수.메서드
studentAhn.studentName = '홍길동'; // studentName 멤버 변수 사용
System.out.print(studentAhn.getStudentName()); //getStudentName()메서드 사용