Results 1 to 2 of 2
  1. #1
    Callofdudey is offline Member
    Join Date
    Sep 2011
    Posts
    10
    Rep Power
    0

    Default What is "reference"? Am I understanding it correct by smiplifying it this way?

    If you use a class like this (BTW I do not know if this kinda usage is legal in java, as point is sorta a instantiated class, or in other words, an object, you can pass an object as parameter of a method, right?)

    Public void moveToNewLoc (point point, int xLoc, int yLoc ) {//method body}

    The textbook tells ya when you pass an object or a class name as parameter or argument (again, can you? Much gratitude if you can tell me), what really has been passed, is a "reference", so, can I understand it this way: it is something very similar to the "pointer" in C, the "reference" is some thingy that contains the address of the memory OF the JVM.


    Am I right, or I completely missed the target?

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: What is "reference"? Am I understanding it correct by smiplifying it this way?

    Pretty much yes. The method declaration
    Java Code:
    public void moveToNewLoc(Point point, int xLoc, int yLoc){...}
    Tells the method it takes a point object. When you pass an actual point in:
    Java Code:
    object.moveToNewLoc(p1, 10, 20);
    the method is being called on a reference to the object. The statement
    Java Code:
    Point p1 = new Point(10, 450);
    Does three things:
    1. Create a reference named p1
    2. Initialize a Point object on the heap
    3. Link the reference to the object on the heap

Similar Threads

  1. Hel me in understanding "builing the project"
    By Anveshan in forum New To Java
    Replies: 1
    Last Post: 09-29-2011, 10:01 AM
  2. Understanding EJB "machine" ;-)
    By cygan in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 09-08-2011, 09:24 PM
  3. understanding the method "length" and how to use it
    By bigsonny in forum New To Java
    Replies: 34
    Last Post: 06-22-2011, 05:02 PM
  4. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

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