Static polymorphism (method overloading)

Theory

Play the guitar

Report a typo

Please have a look at the code below:

class Instrument {
public:
    void sound() { std::cout << "Instrument playing" << std::endl; }
};

class Guitar : public Instrument {
public:
    void sound(int strings) { std::cout << "Guitar strumming with " << strings << " strings" << std::endl; }
};

Suppose, you have created an object named guitar of the Guitar class. You want to check the guitar by printing "Instrument playing". Which function below will perform the job?

Select one option from the list

Create a free account to access the full topic