코딩 오류 13

[코딩 오류 노트] 싱글턴 패턴 객체 생성

주말을 맞아 java 복습을 하다가 싱글턴 패턴으로 객체 주소를 가져오게 되어있을 때 new를 사용해 객체를 생성하면 어떻게 되는지 궁금해져서 해봤다. package Practice; import java.time.LocalDate; public class TimePlus { public static void main(String[] args) { LocalDate ld = new LocalDate(); LocalDate ld2 = LocalDate.now(); System.out.println(ld); System.out.println(ld2); } } 오류 메시지 Exception in thread "main" java.lang.Error: Unresolved compilation problem: T..

오류노트 2023.11.26

[코딩 오류 노트]다형성, 추상 메서드

1. 부모 클래스에 기본 생성자 미입력 오류 메시지 Exception in thread "main" java.lang.Error: Unresolved compilation problem: Implicit super constructor car2() is undefined. Must explicitly invoke another constructor 코드 해결 부모 클래스에 기본 생성자를 추가한다. 이러한 상황이 생기는 것을 방지하기 위해 기본 생성자를 작성해두는 것이 좋다. 2. 추상 클래스에서 정해놓은 추상 메서드를 오버라이딩하지 않음 오류 메시지 The type pikachu must implement the inherited abstract method pokemon.attack() The type..

오류노트 2023.10.23

[코딩 오류 노트] 상속, 오버라이딩

1. 오버라이딩한 함수 static 설정 오류 메시지 This static method cannot hide the instance method from Student1 The method say() of type Leader must override or implement a supertype method Cannot use super in a static context 코드 @Override static void say() { System.out.println("선생님께 인사"); super.say(); 해결 상속받은 메서드를 오버라이딩하면서 스태틱 메서드로 만들 수는 없다. 2. main 메서드에서 super 호출 오류 메시지 Exception in thread "main" java.lang.Err..

오류노트 2023.10.20

[코딩 오류 노트] 클래스 메서드에서 인스턴스 메서드, 메서드 중복/파라미터값

1. 클래스 메서드에서 인스턴스 메서드에 접근 오류 메시지 Cannot make a static reference to the non-static field iv Cannot make a static reference to the non-static method im() from the type Check 코드 //(별개의 클래스) int iv = 4; void im() { } //(메인 클래스 메인 함수 안) static void cm_Imember() { System.out.println(iv); im(); } 해결 클래스 멤버는 인스턴스 멤버를 참조하거나 호출할 수 없다. 2. 메서드 중복 오류 메시지 Duplicate method sum(int a, int b, int c) in type exam..

오류노트 2023.10.19

[코딩 오류 노트] 클래스, 인스턴스, 메서드

1. 클래스 이름 중복 오류 메시지 The type Class_practice is already defined 코드 public class Class_practice { public static void main(String[] args) { Car mycar = new Car(); } } class Class_practice { } 해결 클래스 이름은 중복되지 않도록 한다. 2. 클래스 파일 이름과 퍼블릭 클래스 이름 불일치 오류 메시지 The public type Class must be defined in its own file 코드 public class Class { } (파일명: Class_practice) 해결 클래스 파일 이름과 퍼블릭 클래스를 일치시킨다. 3. 다른 클래스에서 만든 인스..

오류노트 2023.10.17

[코딩 오류 노트] 배열 선언 실수, 배열 인덱스 범위 초과

1. 배열 선언 실수 오류 메시지 Exception in thread "main" java.lang.Error: Unresolved compilation problems: Syntax error, insert ". class" to complete Expression The type of the expression must be an array type but it resolved to Class c cannot be resolved to a variable 코드 int[c] = new int[10]; 해결 int[]c = new int[10]; 배열 길이가 대괄호 안에 들어가는 것과 헷갈리지 않도록 한다. 2. 배열 인덱스 범위 초과 오류 메시지 Exception in thread "main" java..

오류노트 2023.10.16

[코딩 오류 노트] if문, System, printf()/println(), 불필요한 .

1. printf 형식에 println 입력 오류 메시지 Exception in thread "main" java.lang.Error: Unresolved compilation problem: the method println(int) in the type PrintStream is not applicable for the arguments (String, int) 코드 System.out.println("음악을 %d번 재생했습니다.\n", ++count); 해결 (" ", )형식은 printf에서 사용한다. printf(" ", ) println() 2. System.out.println에서 out 미입력 오류 메시지 Exception in thread "main" java.lang.Error: Unr..

오류노트 2023.10.13