Choosing the most restrictive modifier

The class Thermostat is declared public in package home.climate. Its own methods use all of its members, and other classes use them as follows:

  • Field targetTemp: read and written only by Thermostat's own methods.
  • Method adjust(): called by Scheduler, another class in home.climate, and by no class outside that package.
  • Method setMode(): called by Scheduler, and also by SmartThermostat, a subclass of Thermostat in package home.premium that calls it on its own object. No unrelated class outside home.climate calls it.
  • Method getTargetTemp(): called by PhoneApp, an unrelated class in package app.mobile.

For each member, give the most restrictive access modifier that lets every listed use compile. Type the keyword, or type none if the member should have no modifier.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Access Modifiers Questions: