Sunday, August 12, 2007

What's the differences between object and object references?

Student s = new Student("Joe",20);
is an object of class Student. Can we say s is an object reference
class Student?


s is not an object, it's a variable which contains a reference to an object.
Objects don't have names, just types and locations in memory (and, of course,
fields and methods). Read your statement as: Create a new Student object in
memory, initializing it with the data sent as arguments to a constructor, and
when created, assign a reference to that object to the Student variable s. s
is a reference or object type variable which may reference a Student object or
an object of any subclass of Student.

Take another statement: int x = s.getValue();

Read this statement as "Go to the object referenced by variable s and execute
its getValue() method. Assign the return from that method to the int variable
x."

13 comments:

Arsenish said...

You are absolutely amzing, absolutely. I m newbie to programming and have a few knowledge on the basic things but the way you explained the coding is better, by a country mile, than what i have got from any of professors till now. Keep up the good work sir, will bw following your blog timely now on.

Rohit Goyal said...

You are absolutely amzing, absolutely. I m newbie to programming and have a few knowledge on the basic things but the way you explained the coding is better, by a country mile, than what i have got from any of professors till now. Keep up the good work sir

Rohit Goyal said...

You are absolutely amzing, absolutely. I m newbie to programming and have a few knowledge on the basic things but the way you explained the coding is better, by a country mile, than what i have got from any of professors till now. Keep up the good work sir

Anonymous said...

Its really good.

Anonymous said...

This makes complete sense, thanks so much.

kanaparthi kiran said...

simple and precise...

Evariste said...

your explanation is better than 1000 books. short and concise. Thanks, it really helps me to understand what books call "reference object".
Evariste

Anonymous said...

GREAT explanation! I especially like how you explain as if you were "talking it through." That's the hardest part of learning CS for me. If someone would just tell me how I should "think of it"/"talk it through to myself" this would be tons easier.

Anonymous said...

Great explanation Sir! Thanks a lot ..

Unknown said...

Thanks you boss!
it is a simple way to underatand the major diff bw object and reference...

keep answering the que in the simple way....

Anonymous said...

thank u sir, u have given very excellent and in depth answer which everyone can understand.....its a precious thing which must be archived

Unknown said...

greate understanding for the topic

"object doesn't have name"

thank you sir

rajan kumar said...

thank's for clear object and refrence

Topics