Knowee
Questions
Features
Study Tools

Which of the following statements about polymorphism are true? (Choose all that apply)  *2 pointsA. A reference to an object may be cast to a subclass of the object without an explicit cast.B. If a method takes a superclass of three objects, then any of those classes may be passed as a parameter to the method.C. A method that takes a parameter with type java.lang.Object will take any reference.D. All cast exceptions can be detected at compile-time.E. By defining a public instance method in the superclass, you guarantee that the specific method will be called in the parent class at runtime.

Question

Which of the following statements about polymorphism are true? (Choose all that apply)  *2 pointsA. A reference to an object may be cast to a subclass of the object without an explicit cast.B. If a method takes a superclass of three objects, then any of those classes may be passed as a parameter to the method.C. A method that takes a parameter with type java.lang.Object will take any reference.D. All cast exceptions can be detected at compile-time.E. By defining a public instance method in the superclass, you guarantee that the specific method will be called in the parent class at runtime.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct statements about polymorphism are:

B. If a method takes a superclass of three objects, then any of those classes may be passed as a parameter to the method. This is true because in polymorphism, a superclass reference variable can refer to a subclass object.

C. A method that takes a parameter with type java.lang.Object will take any reference. This is true because in Java, the Object class is the root of the class hierarchy. Every class has Object as a superclass, so a method that takes an Object parameter can take any reference.

The other statements are false:

A. A reference to an object may not be cast to a subclass of the object without an explicit cast. You need to explicitly cast it to the subclass.

D. Not all cast exceptions can be detected at compile-time. Some are only detected at runtime, especially those related to downcasting.

E. By defining a public instance method in the superclass, you do not guarantee that the specific method will be called in the parent class at runtime. This is because of method overriding in polymorphism. If a subclass has overridden that method, the subclass's version of the method will be called.

This problem has been solved

Similar Questions

Which of the following statements is false? Group of answer choicesYou can always pass an instance of a subclass to a parameter of its superclass type. This feature is known as polymorphism.The compiler finds a matching method according to parameter type, number of parameters, and order of the parameters at compile time.A method may be implemented in several subclasses. The Java Virtual Machine dynamically binds the implementation of the method at runtime.Dynamic binding can apply to static methods.Dynamic binding can apply to instance methods.

Which of the following statements about polymorphism in Java is true?Question 8Answera.Polymorphism allows an object to take on multiple forms at runtime.b.Polymorphism is achieved through method overriding.c.Polymorphism can only be applied to interfaces, not classes.d.Polymorphism is limited to compile-time behavior only.

Which statement is true regarding polymorphism? a.An overridden method can be less restrictive than the superclass method.b.An overridden method can be more restrictive than the superclass method.c.Overloaded methods cannot change the return type.d.Constructors can be overridden.

ect answerIn which scenario does Java NOT allow polymorphism?OptionsWhen overriding private methodsWhen using interface methodsWhen using the method overloadingWhen using abstract methods

Java classes support runtime polymorphism. Which statement describes what is possible with runtime polymorphism?Instruction: Choose the option that best answers the question. Answer ChoicesMultiple implementations can exist for methods with the same name, with the same input arguments and return valuesCalls to overridden methods are resolved at runtime, hence methods invoked on an object will use the correct implementation based on object typeExactly one implementation can exist for a method with a certain name, and all derived classes have access to these implementationsMethods invoked on objects of the base class type will invoke the base class method implementations

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.