Chapter

Accessor & Mutator Methods

From ComputerScienceOne by Dr Chris Bourke

Concepts

  1. How do member methods differ from static methods?

    "In contrast to the methods we defined in Chapter 29, when defining a member method, we do not use the static keyword. Making a variable or a method static means that the method belongs to the class a

  2. How do accessor and mutator methods use this to access instance variables?

    "Since we have made all the member variables private, no code outside the class may access or modify their values. It is generally good practice to make member variables private to restrict access. Ho

  3. How can getters and setters validate values and support immutable objects?

    "One advantage to using getters and setters (as opposed to naively making everything public) is that you can have greater control over the values that your variables can take. For example, we may want

Accessor & Mutator Methods | ComputerScienceOne | Bifalgorithm | Bifalgorithm