Question: Consider the following code snippet: class Home { public: Home ( ) ; virtual void set _ address ( string new _ address ) ;

Consider the following code snippet:
class Home
{
public:
Home();
virtual void set_address(string new_address);
private:
string address;
string landmark;
};
Home::Home()
{
address ="";
landmark ="";
}
void Home::set_address(string new_address)
{
cout << "Home : set_address function" << endl;
}
class Villa : public Home
{
public:
Villa();
void set_address(string new_address);
};
Villa::Villa()
{}
void Villa::set_address(string new_address)
{
cout << "Villa : set_address function" << endl;
}
int main()
{
Home* q1= new Home;
Villa* cq1= new Villa;
q1= cq1;
q1->set_address("Which function?");
return 0;
}
Which of the following is true about the statement "q1->set_address("Which function?");"?
Question 7 options:
Home::set_address(string new_address) is called by q1 which then calls Villa::set_address(string new_address)
Villa::set_address(string new_address) is called by q1 which then calls Home::set_address(string new_address)
Home::set_address(string new_address) is called by q1
Villa::set_address(string new_address) is called by q1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!