230k views
2 votes
Polymorphism allows you to give the same name to two different methods if the methods are in different classes which are related through inheritance.

A. True
B. False

User Araceli
by
8.2k points

1 Answer

3 votes

Final answer:

The statement about polymorphism allowing the same method name in different classes related through inheritance is true. Polymorphism is central to object-oriented programming and supports methods with the same name behaving differently based on the object type invoking them.

Step-by-step explanation:

The statement is true. Polymorphism is a concept in object-oriented programming that does indeed allow a program to have multiple methods with the same name as long as those methods exist in different classes that are related by inheritance. It is key in allowing an object to take on many forms, thereby facilitating code reusability and scalability.

In the context of Java, for example, when a subclass inherits from a superclass, it can override methods of the superclass. This means that the same method name can behave differently depending on the type of object that invokes the method. This type of polymorphism is known as Run-time Polymorphism or Dynamic Method Dispatch. Additionally, method overloading is another form of polymorphism that happens within the same class where methods have the same name but different signatures (different parameters).

User Codinghands
by
6.9k points