I do not see why the answer E is correct. Please help. Thanks!
The book's answers are A, C, and E.
My answers are only A and C. I don't see why the answer E is correct. There is one private method in Michael's interface that is not accessible in the Twins class. So E cannot be correct.
What statements about the following Twins class are true? (Choose three.)
A. The class fails to compile because of the write() method.
B. The class fails to compile because of the publish() method.
C. The class fails to compile because of the think() method.
D. All of the methods defined in the Alex interface are accessible in the Twins class.
E. All of the methods defined in the Michael interface are accessible in the Twins class.
F. The Twins class cannot be marked abstract.
This question is testing several different pieces of knowledge.
Regarding A, B, C:
All abstract and default methods in an interface are public by default, and can not be made anything less than public in an implementing class.
This is an annoying, but basic Java gotcha, as all methods in classes default to <package> or default access, so those must be explicitly declared public in Twins.
So A and C are both reasons the class fails to compile.
Static methods are not inherited, they are available to an implementing class just the same way they are available to anyone else who can see the interface, so B is not true.
D and E are tricky as hell. The non-static private methods defined in Alex and Michael interfaces can be re-declared in the implementing class, and can be private, default, protected or public.
So the names are available for use, but there is no way that the private methods in the interfaces themselves can be called directly from the implementing class.
The class could call a default method of the interface that calls them indirectly, I just confirmed that by adding calls to the private methods of each interface to their default method write, and that of course works when an instance method of Twins explicitly calls the interfaces default write() methods using and called from Twins.write()
I would not interpret that as either D or E being a correct choice. They can't be directly accessed from the Twins class.
So there are several very tricky things they could potentially have asked, but I conclude they most likely meant to mark only one of those as private and perhaps meant to mark the other one as default, or the answer E is just wrong. If you are missing something here, so am I.
Eventually one or more of the authors will come by to tell us what they meant to do in this question.
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)