3.6. Accessing object fields

[2.3] Know how to read or write to object fields

In this section, you’ll learn what object fields are and how to read, initialize, and modify them. You’ll also learn the correct notation used to call methods on objects. Access modifiers also determine whether you can call a method on an object.

3.6.1. What is an object field?

An object field is another name for an instance variable defined in a class. I’ve often seen certification aspirants who are confused over whether the object fields are the same as instance variables of a class.

Here’s an example of the class Star:

In the preceding example, ...

Get OCA Java SE 8 Programmer I Certification Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.