Results 1 to 2 of 2
Thread: What is this Output !
- 10-28-2013, 10:59 AM #1
Senior Member
- Join Date
- Jul 2011
- Posts
- 112
- Rep Power
- 0
What is this Output !
Java Code:package passbyvaluepracticetest; public class PassReferenceTypeParamenterByValue { public static void main (String []args){ PassReferenceTypeParamenterByValue avien= new PassReferenceTypeParamenterByValue(); PointForPassReferenceTypeParametersByValue p = new PointForPassReferenceTypeParametersByValue(2, 3); System.out.println("The reference variable p which is initially pointing to a Point.. object located at (2,3), inside the method moveP() refers to another newly created object of the same Point.. type located at (10,20).\nThe proof is taking the X and Y position of the Point.. object pointed by the reference variable returned by moveP(); i.e. X:" + avien.moveP(p) + "and Y:" + avien.moveP(p) + ".\n" ); System.out.println("\nBut due to pass by value, outside moveP(), p still refers to the same object. Proof is X: " + p.xPosition + " and Y: " + p.yPosition + "."); } public PointForPassReferenceTypeParametersByValue moveP(PointForPassReferenceTypeParametersByValue del_p){ del_p = new PointForPassReferenceTypeParametersByValue(10, 20); return del_p; } } public class PointForPassReferenceTypeParametersByValue { int xPosition; int yPosition; PointForPassReferenceTypeParametersByValue(int x, int y){ xPosition=x; yPosition=y; } }
The reference variable p which is initially pointing to a Point.. object located at (2,3), inside the method moveP() refers to another newly created object of the same Point.. type located at (10,20).
The proof is taking the X and Y position of the Point.. object pointed by the reference variable returned by moveP(); i.e. X:passbyvaluepracticetest.PointForPassReferenceTyp eParametersByValue@2f78743band Y:passbyvaluepracticetest.PointForPassReferenceTyp eParametersByValue@d16e5d6.
But due to pass by value, outside moveP(), p still refers to the same object. Proof is X: 2 and Y: 3.
QUESTION: -
WHAT IS THIS? X:passbyvaluepracticetest.PointForPassReferenceTyp eParametersByValue@2f78743band Y:passbyvaluepracticetest.PointForPassReferenceTyp eParametersByValue@d16e5d6.Don't forget to smile :-)
- 10-28-2013, 11:55 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 28
Similar Threads
-
XSLT | disable-output-escaping adding a new line to the output
By smarty_m2002 in forum Advanced JavaReplies: 2Last Post: 05-03-2012, 12:39 PM -
how to get the resultset output into an output file
By renu in forum New To JavaReplies: 0Last Post: 09-30-2010, 09:16 PM -
Need help with output
By cedric11 in forum New To JavaReplies: 4Last Post: 11-30-2009, 02:09 PM -
Java, output string, getting correct output? HELP!
By computerboyo in forum New To JavaReplies: 2Last Post: 02-26-2009, 12:44 AM -
different output
By pro85 in forum Java AppletsReplies: 6Last Post: 08-05-2008, 02:42 PM
Bookmarks