Results 1 to 12 of 12
Thread: object and reference
- 04-01-2011, 06:55 PM #1
Senior Member
- Join Date
- Nov 2010
- Posts
- 155
- Rep Power
- 3
object and reference
Hello,
While solving some exercises, i stumbled upon 2 methods of different classes that return an object of type Item, but in the description one of them said "return the Item object" and the other one was "return a reference to the Item object" whats the difference between the two?
Thanks in advance
- 04-01-2011, 07:20 PM #2
In Java, they're the same thing; it's expanding into things like C++ where references and pointers and objects are all different. Can you show the methods?
- 04-01-2011, 07:23 PM #3
Senior Member
- Join Date
- Nov 2010
- Posts
- 155
- Rep Power
- 3
the questions were above in my post and the methods i wrote are here, its an exercise without correction to it, and i wanted to know
this method is when asking for return an Item object:
and this is for returning an Item reference:Java Code:public Item get (int index) { return itemList.get(index); }
Java Code:public Item getItem () { return this.item; }
- 04-01-2011, 07:24 PM #4
Senior Member
- Join Date
- Nov 2010
- Location
- Delhi
- Posts
- 135
- Blog Entries
- 1
- Rep Power
- 0
Both mean the same thing
- 04-01-2011, 07:25 PM #5
Senior Member
- Join Date
- Nov 2010
- Posts
- 155
- Rep Power
- 3
so the methods i wrote are correct, right?
- 04-01-2011, 07:25 PM #6
In Java, only references and primitives are passed and returned. Objects are not.
db
- 04-01-2011, 07:27 PM #7
Senior Member
- Join Date
- Nov 2010
- Posts
- 155
- Rep Power
- 3
- 04-01-2011, 07:27 PM #8
Senior Member
- Join Date
- Nov 2010
- Location
- Delhi
- Posts
- 135
- Blog Entries
- 1
- Rep Power
- 0
- 04-01-2011, 07:28 PM #9
Senior Member
- Join Date
- Nov 2010
- Location
- Delhi
- Posts
- 135
- Blog Entries
- 1
- Rep Power
- 0
- 04-01-2011, 07:29 PM #10
Senior Member
- Join Date
- Nov 2010
- Posts
- 155
- Rep Power
- 3
ahaa, I see
well thnx guys for the help
I appreciate it
- 04-01-2011, 08:32 PM #11
These two pages on another forum's website explain it well.
JavaRanch Campfire - Cup Size: a Story About Variables
JavaRanch Campfire - Pass By Value, Please
db
- 04-01-2011, 08:39 PM #12
Senior Member
- Join Date
- Nov 2010
- Posts
- 155
- Rep Power
- 3
Similar Threads
-
Method, returning reference to an object
By Saletra in forum New To JavaReplies: 3Last Post: 08-23-2010, 08:22 PM -
Object and reference
By katie in forum New To JavaReplies: 2Last Post: 10-19-2009, 03:45 PM -
Very new to Java, how to reference an object
By tornado in forum New To JavaReplies: 3Last Post: 12-05-2008, 12:51 AM -
Object reference to number
By dayneo in forum New To JavaReplies: 4Last Post: 05-27-2008, 01:23 PM -
Getting the Object Reference Name
By Deathmonger in forum New To JavaReplies: 2Last Post: 03-12-2008, 02:51 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks