Objects and Classes

A camping store's program keeps track of its tents, and each tent in the program is an object. The program's Tent class is documented with one constructor.
Tent(int sleeps)
creates a tent that sleeps the given number of people
Classes and objects
The Tent class describes what every tent has and can do. Each tent has attributes, like the number of people it sleeps and whether it's pitched, and behaviors, like being pitched and packed away. The class doesn't hold any one tent's values. It's the blueprint.
An object is one particular tent built from that blueprint. A tent that sleeps 6 and a tent that sleeps 2 are both Tent objects. Each one keeps its own values: one stores 6, the other 2.
Superclasses and subclasses
Related classes can share a class above them. A store might have a Shelter class with what every shelter has, and Tent as a class that extends it. Then Shelter is a superclass and Tent is a subclass. A tent draws on the attributes and behaviors of a shelter without its code repeating them. Every Java class is a subclass of a class named Object, whether or not its code says so. Shelter extends Object directly, and Tent extends it through Shelter. Writing class hierarchies isn't part of this course.
Reference variables
A variable can have a class as its type.
Tent family;
This declares a variable named family whose type is Tent. It doesn't create a tent. A variable whose type is a class stores a reference, which can be thought of as an object's address in memory. So far no tent exists for family to reach.
Creating an object
An object is created with the keyword new and a call to a constructor.
Tent family = new Tent(6);
The right side, new Tent(6), creates a tent that sleeps 6. The left side declares family, and the assignment puts the new tent's reference in it. Without new there's no object, so Tent family = Tent(6); doesn't compile.
Copies of a reference
Assigning one reference variable to another copies the reference. The object itself is never copied this way.
Tent family = new Tent(6);
Tent loaner = family;
There's still one tent. Both family and loaner hold a reference to it, so they're two names for the same object. Only new creates a tent, and it appears once.
null
A reference variable can hold null when it has no object. The store hasn't picked a tent to set up in its window yet.
Tent display = null;
The variable display exists, but it refers to no tent. Once the store chooses one, display = new Tent(4); gives it a tent to refer to.