-1

I get

Exception in thread "main" java.lang.Error: Unresolved compilation problem

from this code:

public class Book2 {
    String title;
    String author;

    void show() {System.out.println(title+" "+ author);

    public Book2() {
        this("", "");
        System.out.println("생성자 호출됨");
    }

    public Book2(String title) {
        this(title, "작자미상");
    }

    public Book2(String title, String author) {
        this.title = title;
        this.author = author;
    }

    public static void main(String[] args) {
        Book2 littlePrince = new Book2("어린왕자", "생텍쥐페리");
        Book2 loveStroy = new Book2("춘향전");
        Book2 emptyBook = new Book2();
        loveStroy.show();
        // bible.show();
    }
  }
}

I do not know which part is the error.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
김태호
  • 3
  • 1
  • 3
  • Welcome to Stack Overflow! Other users marked your question for low quality and need for improvement. I re-worded/formatted your input to make it easier to read/understand. Please review my changes to ensure they reflect your intentions. But I think your question is still not answerable. **You** should [edit] your question now, to add missing details (see [mcve] ). Feel free to drop me a comment in case you have further questions or feedback for me. – GhostCat Oct 15 '18 at 04:31
  • First of all: this exception means: you try to **run** code that didn't compile properly. And then you get that exception. So point 1: dont try to run your code, compile it first, and make sure you fix all error messages. – GhostCat Oct 15 '18 at 04:32

2 Answers2

1

There is also a syntax error here:

void show() {System.out.println(title+" "+ author);

You missed closing brace.

void show() {System.out.println(title+" "+ author);} 



(ins)-> javac Book2.java 
(ins)-> java Book2
생성자 호출됨
춘향전 작자미상
apatniv
  • 1,771
  • 10
  • 13
0

Your code needs UTF-8 encoding checked, the error is because you are using default ASCII encoding.

Right click on your class file in eclipse --> go to properties --> Resource -->Text File endcoding at the bottom --> Select Other and choose UTF-8 from the dropdown.

If you are not using eclipse then while saving your java file save it with UTF-8 encoding.

The error will be gone. And you'll get the output as such -

생성자 호출됨 춘향전 작자미상

amar19
  • 373
  • 1
  • 3
  • 16