What Is an Object?

The previous section focused on classes and ended with a small but complete user-defined class called Timestamp. We've already let the cat out of the bag that an object is a variable of a class type, not a primitive type. There are several other ways to say that:

  • An object is an instance of a class

  • An object belongs to a class

  • An object belongs to a reference type

However, they all mean the same thing. This section fills in some more of the details on objects: how you declare them and how you create them (two different things), and how you use them.

What “reference type” really means

An object declaration looks exactly the same as a primitive variable declaration. You first write the type name (which is the class ...

Get Just Java™ 2 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.