Given:
public interface Builder {
public A build(String str);
}
and
Assuming that this code compiles correctly, which three statements are true? (Choose three.)
Given:
public interface Builder {
public A build(String str);
}
and
Assuming that this code compiles correctly, which three statements are true? (Choose three.)
Given the provided interface and implementation, certain conditions must hold for the code to compile correctly. First, B must be a subtype of A because the return type of the build method in BuilderImpl must be covariant with the return type of the build method in Builder. Therefore, B is a subtype of A. Second, since you can instantiate B using new B(str), B cannot be abstract, as abstract classes cannot be instantiated. Lastly, A cannot be final because you cannot have a final class be a superclass to another class. Thus, the correct statements are that A cannot be final, B cannot be abstract, and B is a subtype of A.
The correct answers are B. A cannot be final, C. B cannot be abstract, and E. B is a subtype of A. Since the code compiles correctly, the method build in the BuilderImpl class must be a valid implementation of the method declared in the Question70 interface. This means that the return type of the build method in the BuilderImpl class, which is B, must be a subtype of the return type of the build method in the Builder interface, which is A. Therefore, option E is correct.
correct answer is B,C,E
answer: EBC E correct the signature of the implementation method must be the same the return type must be compatible(covariant) between the implementation and interface methods -- B correct because of E -- C correct return new B(str) Abstract classes cannot be instantiated
BCE are correct
B. A cannot be final (So B in impl throw compilation error because B cannot extends A) C. B cannot be abstract (so cannot do new B()). E. B is subclass of A (method is overriding so then => B is A
B. A cannot be final. C. B cannot be abstract. E. B is a subtype of A.
correct answer is B,C,E
B, C, F