asked 180k views
5 votes
Four things we can do with an inherited method: When a subclass inherits a method from its superclass, What are the four things we can choose to do in the subclass?

1) Override the method with a new implementation
2) Add additional functionality to the inherited method
3)all the superclass method and add additional functionality
4)o nothing and use the inherited method as is

asked
User Retronym
by
8.3k points

1 Answer

4 votes

Final answer:

When a subclass inherits a method from its superclass, there are four things we can choose to do in the subclass: override the method with a new implementation, add additional functionality to the inherited method, call the superclass method and add additional functionality, or do nothing and use the inherited method as is.

Step-by-step explanation:

When a subclass inherits a method from its superclass, there are four things we can choose to do in the subclass:

  1. Override the method with a new implementation: In this case, the subclass provides its own implementation of the method, which replaces the implementation inherited from the superclass.
  2. Add additional functionality to the inherited method: Here, the subclass extends the functionality of the inherited method by adding new instructions or logic to it, while still using the superclass's implementation.
  3. Call the superclass method and add additional functionality: This involves invoking the superclass's implementation of the method using the super keyword, and then adding additional instructions or logic to it.
  4. Do nothing and use the inherited method as is: If the subclass does not override or extend the method, it will use the inherited method as is, without any modifications.

answered
User Swuk
by
8.4k points