Question: The following code generates an error. Why? class Player { public: void SetName ( string newName ) { . . . } private: void SetAge

The following code generates an error. Why?
class Player {
public:
void SetName(string newName){...}
private:
void SetAge(int newAge){...}
};
class SoccerPlayer: public Player {
public:
void SetDetails(string newName){...}
string GetLeague(){...}
};
int main(){
string leagueName;
SoccerPlayer playerObject;
playerObject.SetName("Tim Allen");
playerObject.SetAge(21);
leagueName = playerObject.GetLeague();
}
Group of answer choices
playerObject.SetAge(21)
will generate an error as SetAge is private member which is not inherited by the SoccerPlayers class.
leagueName = playerObject.GetLeague()
will generate an error as the derived class should not call its own members.
playerObject.SetName("Tim Allen")
will generate an error as SetName is not declared in class SoccerPlayers.
SoccerPlayer playerObject
will generate an error as an object of derived class cannot be created.

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 Finance Questions!