Skip to content

Instantly share code, notes, and snippets.

@vanderhoop
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save vanderhoop/de72f5800be4a0f6bbc6 to your computer and use it in GitHub Desktop.

Select an option

Save vanderhoop/de72f5800be4a0f6bbc6 to your computer and use it in GitHub Desktop.

More Getter and Setter Methods

You just learned how to define getter and setter methods to a class definition, and also how use them in a program. Put your newfound knowledge to use.

Exercise Objectives

  • get meaningful reps defining getter and setter methods within a class definition
  • user setter methods to set attributes of an object
  • user getter methods to retieve attributes of an object

Directions

  1. Within your User class definition, write a getter and setter method for an age attribute.
  2. Test your new getter and setter method for age, setting an age to a user and retrieving the value.
  3. Great, now write a getter and setter method for an gender attribute.
  4. Test your new getter and setter method for gender, setting a gender to a user and retrieving the value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment