OCA Java SE 8 Class Design - OCA Mock Question Class Design 14








Question

Which of the following statements about polymorphism are true? (Choose all that apply)

  1. A reference to an object can be cast to a subclass of the object without an explicit cast.
  2. If a method takes a superclass of four objects, then any of those classes may be passed as a parameter to the method.
  3. A method that takes a parameter of type java.lang.Object will accept any reference including null.
  4. All cast exceptions can be detected at compile-time not runtime.
  5. A public instance method in the superclass can be guarantee called in the parent class at runtime.




Answer



B, C.

Note

A reference to an object requires an explicit cast if referenced with a subclass, A is incorrect.

Because of polymorphic parameters, if a method takes the superclass of an object as a parameter, then any subclass references may be used without a cast, so B is correct.

All objects extend java.lang.Object, if a method takes that type, any valid object, including null, may be passed; C is correct.

Some cast exceptions can only be detected at runtime, D is incorrect.

Because of polymorphism, a public instance method can be overridden in a subclass and calls it via reference to superclass, so E is incorrect.