Results 1 to 4 of 4
  1. #1
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Concept of Pass by Reference in Java

    Hy guys ... I have used C++ so I wanna ask ..Is there any concept of pass by reference in Java ?

  2. #2
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Concept of Pass by Reference in Java

    Elaborate please

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: Concept of Pass by Reference in Java

    Nope.
    Java is pass by value.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,783
    Rep Power
    5

    Default Re: Concept of Pass by Reference in Java

    Only in the sense that objects and arrays are treated as references (I think of them as quasi pointers). But you can't do this in Java.
    (Pardon my syntax, it has been decades since I programmed in C).

    int a = 0;
    changeA(&a);
    // a should now be 5.
    void changeA(int *a) {
    *a = 5;
    }

    You can only alter what the reference refers to, not the reference itself.

    EDIT: Long winded explanation of what Toll's said. Pass by value only.

    Regards,
    Jim
    Last edited by jim829; 05-15-2013 at 05:26 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. pass by reference?
    By wayenng in forum New To Java
    Replies: 7
    Last Post: 12-24-2012, 06:36 PM
  2. static variable /pass by reference
    By katturv in forum New To Java
    Replies: 15
    Last Post: 10-03-2010, 08:17 AM
  3. How to create pass by reference??
    By --> xeiyne! in forum CLDC and MIDP
    Replies: 4
    Last Post: 04-08-2010, 06:43 PM
  4. Don't pass by reference
    By Lyven in forum Advanced Java
    Replies: 6
    Last Post: 11-16-2009, 06:06 PM
  5. Pass-by-reference
    By popjava in forum New To Java
    Replies: 1
    Last Post: 10-19-2009, 03:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •