57.8k views
4 votes
Which of the following statements is true? group of answer choices every method in a subclass must override a superclass method.

a. a method that is overridden in a subclass can perform a task that is totally different from the task performed by the same method in the superclass.
b. a method that is overridden in a subclass cannot invoke the method in the superclass with the same name.
c. a method that is overridden in a subclass must extend the functionality of the superclass by invoking the superclass method.
d. Every method in a subclass must override a superclass method.

1 Answer

2 votes

Final answer:

The correct answer is option c. A method that is overridden in a subclass must extend the functionality of the superclass by invoking the superclass method.

Step-by-step explanation:

The correct answer is option c. A method that is overridden in a subclass must extend the functionality of the superclass by invoking the superclass method.

When a method is overridden in a subclass, the subclass can provide a new implementation for that method. However, if the subclass wants to extend the functionality of the superclass method, it can invoke the superclass method using the super keyword. This allows the subclass to add additional functionality while still utilizing the original implementation from the superclass.

For example, consider a superclass Animal with a method makeSound(). If the subclass Dog wants to override the makeSound() method, it can provide its own implementation, but it can also invoke the makeSound() method from the superclass using super.makeSound(). This way, the Dog class can extend the functionality of the Animal class's makeSound() method.

User Alex Curtis
by
8.3k points