aspose file tools*
The moose likes Beginning Java and the fly likes my instance variable values can be diffferent from my buddy's values. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "my instance variable values can be diffferent from my buddy Watch "my instance variable values can be diffferent from my buddy New topic
Author

my instance variable values can be diffferent from my buddy's values.

Tomendra Singh
Ranch Hand

Joined: Jun 28, 2008
Posts: 47
hi all,

i am studying head first java and in chapter 2 there is a line "my instance variable values can be diffferent from my buddy's values."

i am not able to understand it,can anybody help me with some example.


thank you.


Strength Is Life,Weakness Is Death- Swamy Vivekanand.
SCJP 5.0(87%)
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11422
    
  16

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
Tomendra Singh
Ranch Hand

Joined: Jun 28, 2008
Posts: 47
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."

what does that mean "buddy's values"
Kyle Teeger
Greenhorn

Joined: Oct 27, 2008
Posts: 2
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.

Mustang.Color = "Red"
Bronco.Color = "Blue"

Hope this helps.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11422
    
  16

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: my instance variable values can be diffferent from my buddy's values.