Please enable JavaScript to use CodeHS

Chapter 5

Writing Classes

5.4 Accessor Methods

Accessor Methods

The Return Value

The toString Method

Student Getter Methods

SuperHero Class with Secret Identity

Check Your Understanding

  1. Invalid Answer

Exercise: Text Messages Getter Methods

Vocabulary

Term Definition
Accessor Method A method that enables user to obtain information about an object’s instance and static variables.
toString Method A specific accessor method that returns a String value with information about an object’s instance values. This overrides the object’s inherit toString method when an object is printed using System.out.print or System.out.println