From the course: Java 8 Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Working with object data types

Working with object data types - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Working with object data types

- So far, I've described variables in Java that use the primitive data types: numbers, characters, and booleans. But there's a whole other category of Java variables that are references to objects. An object in Java is an instance of a Java class. When you create a variable, and you point it at an object, the variable isn't the object itself. Instead, it's simply referencing the object. And you can actually have multiple reference variables that are pointing to a single object in memory. So, you might declare an object that has a name of anObject, and then you might have three different variables that are all pointing to the same thing. If something changes about that object in memory, all three of those variables would update. Here's an example: let's say that I've defined a Java class. This class is named ClothingItem, and I've declared a string variable that's a member of the class. Notice that this string variable doesn't have the word static. That means it's something called an…

Contents