Folks,
I'm working with APress
SCJP exam book.
In the final
test I found one qeustion(No 7 in final test):
1. interface Animal {
2. void saySomething();
3. }
4. class farm {
5. void setName(String name){};
6. }
7. // insert code here
8. public class Cow implements Pasture {
9. public void graze() { }
10. void saySomething(){}
11.}
Which of the following code lines inserted independently at line 7 will make this source file compile?
A. interface Pasture {void graze();}
B. interface Pasture {void graze(){}}
C. interface Pasture extends Animal{void graze();}
D. interface Pasture extends Animal{void saySomething(){}}
E. interface Pasture implements Animal{void graze();}
What are your candidates?
B and D is wrong because you cannot implement a method in interface.
E is wrong because interface can extends not implement another interface.
A is OK.
How about C? It looks good but when we look carefully we can see that in
Cow class the method saySomething is marked as a default.
This method is also declared in Animal interface, also without any
word about public. But all methods, variables in interfaces are public.
So C is not correct because if Pasture implement Animal than the Cow class will not compile.
Please correct me if I'm wrong.
Thanks,
Tomek