OCP Question 37, Explanation


interface Answerable {
    public void answer(String question);

Which two class definitions compile?

A. abstract class Test implements Answerable {
       public void write(String essay) { }
B. abstract class Exam implements Answerable {
       public abstract void answer(String str) { }
       public void faint(Boolean bool) { }
C. class Quiz implements Answerable {
       public void answer(Integer num) { }
D. class BlindDate implements Answerable {
       public void answer(Integer age) { }
       public String grin(Integer numberOfMissingTeeth) { }
E. class Interrogation implements Answerable {
       public void answer(String nameAndRank) { }
       public void answer(Integer serialNumber) { }
       public void refuse(String otherQuestions) { }

The correct answer is AE.

You probably remember that we had something very similar on our OCA exam. Option A is correct because Test is abstract and, therefore, does not have to implement Answerable’s answer(). Option B’s answer() has body yet proclaims itself as abstract, the Quiz class in option C is concrete but does not override answer(String), and option D is guilty on two counts: similarly to option C, it defines an overloaded answer(Integer) instead of answer(String) and, what’s more, its grin() misses not only teeth but the return stat, as well.

Leave Comment

Your email address will not be published.