43.1k views
5 votes
When you overload a method defined in a superclass, you must do which one of these?1. Change either the number, type, or order of parameters in the subclass.

2. Use an access specifier that is at least as permissive as the superclass method
3. Return exactly the same type as the original method.
4. Use exactly the same number and type of parameters as the original method.

1 Answer

2 votes

Answer:

Option 1: Change either the number, type, or order of parameters in the subclass.

Step-by-step explanation:

Overloading can be defined as using more than one methods in a class that have same name.

This confuses the two methods as both have same names. Therefore, while overloading there is kept some change in parameters of the methods. This change can be in following ways:

  • Changing order of the parameters from the original method.
  • Changing number of parameters i.e deleting or adding new parameters.
  • Changing the type of parameters used former.

Forexample:

If a method is created as:

Car(char color, char name, int model)

it can be overloaded by using the following method in the same class:

Car(int model, char color, char name)

(The sequence of the parameters is changed.)

i hope it will help you!

User Coryan
by
5.2k points