Which can fill in the blank Main class to compile and logically complete the code? (Choose two.)
public class Test { boolean pass; protected boolean passed() { return pass; } /*from www .j a v a2 s. c om*/ } class Main extends Test { private Test oca; private Test ocp; // assume getters and setters are here }
passed()
{ return oca.pass && ocp.pass; }passed()
{ return oca.passed()
&& ocp.passed()
; }passed()
{ return super.passed()
; }passed()
{ return oca.passed()
&& ocp.passed()
; }passed()
{ return oca.pass && ocp.pass; }passed()
{ return super.passed()
; }D, E.
Since Main is a subclass of Test, it cannot have a more specific visibility modifier.
Test uses protected, which is broader than package-private in Main.
This rules out Options A, B, and C.
The other three options all compile.
However, Option F has a problem.
Suppose your Main object has an Test object with pass set to true for both the oca and ocp variables.
The implementation in Option F doesn't look at either of those variables.
It looks at the superclass's pass value.
This isn't logically correct.
Therefore, Options D and E are correct.