public 클래스는 하나뿐이며 public 클래스와 자바 파일 이름은 같아야 한다.
package chap6;
class BirthDay {
int day;
int month;
int year;
public void setYear(int year){
this.year = year;
}
public void printThis(){
System.out.println(this);
}
}
public class ThisExample {
public static void main(String[] args){
BirthDay bday = new BirthDay();
bday.setYear(2000);
System.out.println(bday);
bday.printThis();
}
}
클래스가 두 개 이지만 public 클래스는 아래의 ThisExample 하나이다.
public 클래스의 이름과 파일 이름이 다르거나 public이 두 개 거나 하면 오류가 난다.

'오류, 기능, 문제해결(JAVA)' 카테고리의 다른 글
| 두 수를 나누는데 소수점을 활용해야함 (0) | 2024.12.23 |
|---|---|
| static 문제 연습 중에 (0) | 2024.12.16 |
| 자바 별찍기 (0) | 2024.12.10 |
| for문 실행순서, 그리고 그 때문에 생긴 while과 결과 차이 (0) | 2024.12.10 |
| for, while반복문 실행과정(참고용) (0) | 2024.12.10 |