PASS - TAKER : Anonymous

Java SE 8 - OCA Object Orientation

Correct : 10

66% Complete (success)

66 %

False : 5

33% Complete (success)

33 %

Anonymous 2018-10-25T22:49:37


1. Given: {code} Which is a correct class? (Choose all that apply.)

B is correct because an abstract class need not implement any or all of an interface’s methods. E is correct : the class implements the interface method and additionally overloads twiddle(). A is incorrect because abstract methods have no body. C is incorrect because classes implement interfaces; they don’t extend them. D is incorrect because overloading a method is not implementing it.


2. Given: {code} What is the result?

The implied super() call in Bottom2’s constructor cannot be satisfied because there is no no-arg constructor in Top. A default, no-arg constructor is generated by the compiler only if the class has no constructor defined explicitly.


3. Given: {code} What is the result?

Although a final method cannot be overridden, in this case, the method is private and, therefore, hidden. The effect is that a new, accessible, method flipper is created. Therefore, no polymorphism occurs in this example, the method invoked is simply that of the child class, and no error occurs.

Not Correct

5. Given: {code} What is the result?

Static init blocks are executed at class loading time; instance init blocks run right after the call to super() in a constructor. When multiple init blocks of a single type occur in a class, they run in order, from the top down.


6. Given the following: {code} Which of the following, inserted at line 9, will compile? (Choose all that apply.)

Before you can invoke Y’s do2 method, you have to cast x2 to be of type Y.


7. Given: {code} What is the result? (Choose all that apply.)

It’s legal to overload main(). Since no instances of Locomotive are created, the constructor does not run and the overloaded version of main() does not run.

Not Correct

8. Given: {code} What is the result? (Choose all that apply.)

Class Dog doesn’t have a sniff method.

Not Correct

9. Given: {code} What is the result? (Choose all that apply.)

A ClassCastException will be thrown when the code attempts to downcast a Tree to a Redwood.


10. Given: {code} What is the result?

The code is correct, but polymorphism doesn’t apply to static methods.


11. Given: {code} What is the result?

Watch out, because SubSubAlpha extends Alpha! Because the code doesn’t attempt to make a SubAlpha, the private constructor in SubAlpha is okay.


12. Given: {code} What is the result?

Remember that constructors call their superclass constructors, which execute first, and that constructors can be overloaded.


13. Given: {code} What is the result?

Polymorphism is only for instance methods, not instance variables.

Not Correct

14. Given: {code} What is the result? (Choose all that apply.)

Neither of these lines of code uses the correct syntax to invoke an interface’s static method.

Not Correct

15. Given: {code} What is the result?

This is kind of a trick question; the implementing method must be marked public. If it was, all the other code is legal, and the output would be 3. If you understood all the multiple inheritance rules and just missed the access modifier, give yourself half credit.


16. Given: {code} Which line(s) of code, inserted independently at // INSERT CODE HERE, will allow the code to compile? (Choose all that apply.)

A uses correct syntax to invoke the class’s method, and C uses the correct syntax to invoke the interface’s overloaded default method.