A class is a recipe.
An object is what you have cooked with it.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
(This is based on my experience with Java - other languages may vary)
A class is the template from which an object is created. A class defines object, an object instantiates the class.
The main difference is how they go about existing on the stack.
When a class is loaded, space is allocated for any static variables. These are shared by all objects of the class, or can be accessed without any obects being created (see java.Math, for example).
When an object is created, it gets a piece of the heap to store its instance variables, which belong to it alone.
As a consequence of this, static and instance fields behave quite differently. Suppose you have a class Car which has a public static int field called "NUMBER_OF_WHEELS". This is a static, so every Car that exists as an instantiation of this class will have the same NUMBER_OF_WHEELS. Suppose that Car also has an instance field - private Color color. This field is allocated for each Car, and can't be referred to without the reference to that particular car - and each car has an independent value for "color". You can't get at Car.color, because it doesn't exist. If I were to change the NUMBER_OF_WHEELS field to 3, every car loses a wheel. If I give my car a new paint job (and change its "color" to Color.PLAID, for example) your car is safe (you can keep your polka dots).
You should note that although all three of the answers you see here look quite different, they're all different ways of saying much the same thing.
jon.kiparsky
Posting Virtuoso
1,849 posts since Jun 2010
Reputation Points: 383
Solved Threads: 187
I'm approcimiately with @ddanbe: A class describes how an object will behave, an object behaves that way. This is very cool because we humans are used to dealing with actual real world objects that have behavior conditioned on what class of object they are: ATMs behave one way, and automobiles another way; and we expect other automobiles to be like our automobile; and we expect an ATM to be like another ATM. So using classes and objects in programming makes programming more familiar to us, and that makes us more efficient programmers. At least that's the idea.
griswolf
Veteran Poster
1,165 posts since Apr 2010
Reputation Points: 344
Solved Threads: 256