Anatomy of a Class

A class is made of a class declaration, instance variables, constructors, and methods. The Backpack class below has all four.
public class Backpack
{
private int items;
private double kilograms;
public Backpack()
{
items = 0;
kilograms = 0.0;
}
public void pack(double kg)
{
if (!isOverweight(kg))
{
items++;
kilograms = kilograms + kg;
}
}
public int getItems()
{
return items;
}
private boolean isOverweight(double kg)
{
return kilograms + kg > 9.0;
}
}
The parts
The first line declares the class with the keyword class. The two instance variables, items and kilograms, are declared inside the class and outside every method and constructor, and every Backpack object has its own pair. The constructor has the class's name and no return type, and it sets up each new object. The methods pack, getItems, and isOverweight run when they're called.
Private means inside this class
The method pack calls isOverweight, which is private, and that's allowed, because pack is code inside Backpack. Inside its own class a private member is used as freely as any other.
From another class, the same members look different.
Backpack trip = new Backpack();
trip.pack(1.5); // compiles, pack is public
double w = trip.kilograms; // doesn't compile, kilograms is private
Calling trip.isOverweight(2.0) from another class fails the same way. Both fail only because of where they're written. Keeping kilograms private means every change to it goes through pack, which checks the 9-kilogram limit first. Code in another class can't skip the check.
One set of variables per object
Each call to new builds an object with its own copies of the instance variables.
Backpack school = new Backpack();
Backpack hiking = new Backpack();
school.pack(2.0);
school.pack(1.0);
hiking.pack(4.0);
System.out.println(school.getItems() + " " + hiking.getItems());
This prints 2 1. The two packs start the same, but packing one never changes the other.