Junior — Middle
Can it be said that inheritance provides objects with the ability to demonstrate different behaviors when using the same interface?
sobes.tech AI
Answer from AI
Yes, inheritance in object-oriented programming allows creating class hierarchies where subclasses can override methods of the base class. This enables objects of different classes to exhibit different behaviors when using the same interface (set of methods). This mechanism is called polymorphism.
For example, if there is a base class Animal with a method make_sound(), then subclasses Dog and Cat can implement this method differently, but when calling make_sound() through a reference to the base class, the behavior of the specific object will be executed.