61.9k views
21 votes
Zohan uses the following analogy to describe a concept of object-oriented programming. A button can have many uses. When it is pressed, it can cause a variety of different outcomes, such as opening a door or changing the volume. But you don't need to know what the button is going to do in order to operate it-you just push it. Which concept is he most likely talking about?

a) polymorphism
b) inheritance
c) encapsulation
d) overriding


User A Poor
by
3.3k points

1 Answer

8 votes

Answer:

Polymorphism

Step-by-step explanation:

You can have a basic button class that gets inherited by other classes.

class Button {

function pushButton(){}

}

class ElevatorButton extends Button{};

class BigRedButton extends Button{};

With these new classes, they inherit from the basic button class. They can decide what happens when the method pushButton() is called.

You don't need to worry about what pushButton() actually does, you can just call it if the object is of the type "Button" and you can expect it to work.

User Lavixu
by
3.5k points