클래스 정의는 class 키워드 뒤에 클래스 이름이 오는 것으로 시작합니다. 한 쌍의 중괄호로 묶인 클래스 본문입니다.
다음은 구문입니다 -
<access specifier> class class_name {
// member variables
<access specifier> <data type> variable1;
<access specifier> <data type> variable2;
...
<access specifier> <data type> variableN;
// member methods
<access specifier> <return type> method1(parameter_list) {
// method body
}
<access specifier> <return type> method2(parameter_list) {
// method body
}
...
<access specifier> <return type> methodN(parameter_list) {
// method body
}
} 다음은 클래스 이름에 대한 규칙입니다 -
파스칼 케이스
클래스 이름에 대한 코딩 규칙은 클래스 이름의 이름입니다. 예를 들어 PascalCasing −
public class CalculateCost {
} 위의 클래스 이름 CalculateCost는 PascalCasing에 있습니다.
명사 또는 명사구
클래스 이름을 명사 또는 명사구로 추가하는 것을 선호 -
public class Department {
}