The output is correct. Here's what's happening "apple juice" (from the System.out in the transform() method) "apple orange" (the fruit1 in the growFruit() is "apple" and the fruit2 is "orange" since transform() returns "orange")
Hope it's clear enough for you.
SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
I have modified the code a little bit. First fruit1 is "apple", then when transform is called, fruits is assigned "apple". When fruits = fruits + " juice"; is executed, after that fruits has the value "apple juice" (fruit1 in main is still "apple"). Now fruits is displayed so "apple juice" is displayed. Then the method returns "orange". This value get's assigned to fruit2. Now fruit1 is displayed which displays "apple" and fruit2 is displayed which displays "orange". So the final output is
String fruit2 = transform(fruit1); ----->while invoking this method fruit2 will contain "apple juice" and "orange".am i right?
I think you are confused here. When transform is called, fruit1's value will be copied to fruits (as per my code). Then the method will return "orange". So fruit2 will contain "orange". "apple juice" has no concern with main method. It will be displayed in transform method...