eh3rrera / ocpj8-book

Study guide for the Oracle Certified Professional, Java SE 8 Programmer Exam (1Z0-809)
Other
129 stars 90 forks source link

Answer key to Question5 From Interface chapter is wrong #70

Closed protyay closed 6 years ago

protyay commented 6 years ago

The answer key to the following question of Chapter 4(Q5) is Compilation Fails.

interface F {
    static void test() {
        System.out.println("F test");
    }
}
public class Question_4_5 implements F {
    public void test() {
        System.out.println("Q test");
    }
    public static void main(String[] args) {
        F q = new Question_4_5();
        q.test();
    }
}

I've executed the bit of this code and this compiles just fine and the output is "Q test". Requesting you to please update the answer key accordingly.

eh3rrera commented 6 years ago

Are you sure? Are you testing with Java 8?

I don't know if I'm missing something but I get a compiler error:

untitled-1

protyay commented 6 years ago

@eh3rrera I'm extremely sorry. I did happen to invoke the test routine on the reference type of the concrete class and NOT the interface. Sorry for bothering you..

Keep up the great work.

eh3rrera commented 6 years ago

Don't worry, thanks! 👍