Java in 21 Days (6th Edition) Day 6: Packages, Interfaces, and Other Class Features

The cover of Teach Yourself Java in 21 Days (6th Edition) by Rogers Cadenhead

Home Feedback Other Books Previous Day Next Day

Notes and Corrections

  • View the Certification Practice quiz solution
  • Certification answer: Answer (b) is correct. All three of these instance variables are available for use in the EvenMoreInformation class. The quantity variable is defined in the class, so it can be accessed within the class. The duration variable is defined in the Information class with the public modifier, so it can be accessed from any other class. The rate variable is defined in the Information class with the protected modifier, so it can be accessed from that class and any of its subclasses, even if they do not belong to the same package.

    Answers (a), (c), and (d) are incorrect. All of them refer to average, an instance variable in the Information class defined with no modifier. Any variable defined without an access modifier can be used in that class and subclasses that belong to the same package, but not in subclasses that belong to a different package. Since the Information class is part of the org.cadenhead.bureau package and the EvenMoreInformation class is part of the org.cadenhead.bureau.us package, the average instance variable is not visible in EvenMoreInformation.

Source Files

Activities