This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Quick question about these 3 lines of code Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Quick question about these 3 lines of code" Watch "Quick question about these 3 lines of code" New topic
Author

Quick question about these 3 lines of code

andrew dale
Ranch Hand

Joined: Aug 15, 2011
Posts: 45
First line: setting the 0 object to size 30

Second line: Declaring variable X as pet 0 get size? <--- Confused part

Third Line: setting first pet to size of 8



You'll never achieve your goals if you don't take that chance, so go pry open that trunk and get those amps.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32675
    
    4
You have presumably already initialised the two objects in that array, otherwise you will suffer an Exception.
Whichever class is in that array has a size field, with get and set methods. You start by using the set method to give the size field of the 1st element the value 30.
Then you retrieve the same value from the get method (presumably still 30) and assign it to x. Because it is a primitive (int), there are now two copies of 30 around.
Then you get the 2nd element in the array and use its set method to assign 8 to its size field.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9948
    
    6

It is also entirely possible that the setSize method has logic in it that prevents you setting the size to 30. Maybe it only allows sizes to between 1 and 10, and if you pass it something larger, it reduces it down to 10.

Without seeing the code of setSize(), we really don't know what it could be doing.


Never ascribe to malice that which can be adequately explained by stupidity.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Quick question about these 3 lines of code
 
Similar Threads
Unable to create an array through reference
Are my notes correct
also need help this code
Displaying things...need help badly!! Please!
Question on Bitwise Conditional Operator