Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
Q 10, Self test, K and B.
K Raj Kumar
Greenhorn
Posts: 17
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Ranchers,
class Box{ int size; Box(int s) { size=s :wink: } public class Laser{ public static void main(String[] args){ Box b1= new Box[5]; Box[] ba= go(b1, new Box(6)); ba[0]= b1; for(Box b: ba) System.out.print(b.size + " "); } static Box[] go(Box b1, Box b2) { b1.size=4; Box[] ma= {b2,b1); return ma; } }
Output: 4 4
Source:
SCJP
6.0 guide(K and B), page 274.
Please help me in understanding the output.
Thanks in advance.
With Regards,<br />K.Raj Kumar.
jean-gobert de coster
Ranch Hand
Posts: 49
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
well, b1 has a size of 5 and b2 has a size of 6, then the go method modified b1 so its size is 4 and then returned a Box[] containing {b2, b1}
then ma[0] = b1 so this is the same as saying b2 = b1
so b1.size = 4 and b2.size = 4, hence the output
K Raj Kumar
Greenhorn
Posts: 17
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks Jean..
With Regards,<br />K.Raj Kumar.
Get out of my mind! Look! A tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Array references as arguments in overloaded methods
static variable vs final variable!
Mock question.
Dans Garbage Collection
one more question in GC
More...