Exercise on Composition

Here is an exercise you can solve to test your understanding!

We'll cover the following

Question

Looking at the User / Player example, you might have noticed that we composed Player using User. This means that a Player should be able to access methods defined in the User struct. In the code given below, add additional code to the GreetingsForPlayer function so that it uses the Greetings function from the User struct to print the string that the Greetings function is printing right now:

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy