Originally posted by geetanjali rajput: i really need to ask this. can i say an object is the blue print of a class?. can i say an object is the class itself? i know this is a simple ques. but as a biggener i really need to know it.
I think you have the terminology backwards. A "class" is a blueprint for an "object." A class (as you define in your .java file) describes what data and methods comprise any object of that type. For example. Let's say you have a class called Car:
In this example, I have a class called Car. This is my blueprint. It says that all Cars will have a color, a make, a model, and a year. Also, all cars will be able to drive. In the main method, I create to Car objects. Each of these is made from the blueprint of the Car class, but each one has its own specific details. For example, the first one if a White, '98 Ford Mustang, while the second is a Black, 2000 Pontiac Grand Prix. They're both Cars, yet they're both distinct objects. I hope that helps clear that up for you. Corey
Agreed. If you prefer we could use words like "template", "abstraction", "basis" etc... A class, analogously speaking, is a recipe for chocolate chip cookie, while an object is an actual chocolate cookie, a particular chocolate cookie with its own identity .
A class is collection of objects
Well, no, but you can imagine a class as a "something" that a collection of objects has in common. They may all have a certain element (having warm blood, having a certain volume, whatever), or share a common behavior (being able to run, being able to sing, whatever). I recommend you grab a good OO book. My particular bias is Grady Booch's Object Oriented Analysis and Design where IMHO he has a particularly succinct discussion of the object model. Others will offer their own preferences, surely... -anthony [ April 02, 2002: Message edited by: Anthony Villanueva ]
Perhaps what Dan is trying to say is that when you reference a class, it is loaded into memory one time, in a classfile. That holds all the static variables and the methods. Then there can be as many objects (instances) of that class as is required. The object only holds the state of the member variables for that instance - so that at any time you know what that particular object's variables values are. Each object of that class has the same blueprint for member variables, but those variables can have different values or references in each instance.
"JavaRanch, where the deer and the Certified play" - David O'Meara