my car is (probably) a different color than your car, even if we both own ford mustangs.
an 'instance' refers to a specific object that has been created of a given class. each and every car that rolls of the assembly plant is an instance of the car, with it's own color, VIN, odometer reading, etc, but they are all of the same 'Ford Mustang' class. [ October 27, 2008: Message edited by: fred rosenberger ]
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: Jun 28, 2008
i need some more clarification, still i have not understood.
i am repeating my query, "object says-- my instance variable values can be diffferent from my buddy's values."
I think the book is referring to "buddy's" as another implementation of the respective class. For example, you have your blueprint/superclass named Car with an String instance variable of Color. Now you have two classes that extend Car named Mustang and Bronco. Both of the subclasses will have access to their own Color instance variable from Car, however; it can have different values.
They simply mean that two different instances of the class can have different values.
Let's say there exists a factory method called "getMustang()". You call it like this:
Mustang myMustang = getMustang("Blue");
you get a blue mustang. Now you're a nice guy. you have a buddy or friend who wants a mustang, but he wants a red one. So, you can call the method again:
Mustang myBuddysMustang = getMustang("Red");
now you have two Mustang objects - one is yours, and one is your buddy's. Both have a 'color' instance variable to hold what color the Mustang is, but the two (yours and your buddy's) hold DIFFERENT values.