Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   Objects... (http://www.programmingforums.org/showthread.php?t=7341)

Writlaus Dec 1st, 2005 4:29 PM

Objects...
 
Not sure if this question is Java-specific or not, but in the following example code...

:

class Ball {
    ...
}

Ball newball=new Ball();
anotherVariable=newball;


Does anotherVariable just point to newball? Does it duplicate it?

groovicus Dec 1st, 2005 4:57 PM

Try this, and you tell me: :)

:

public class Test {

    public Test() {
    }
 
    public static void main(String[] args) {
        Test c = new Test();
        Test d = c;
        System.out.println(c);
        System.out.println(d);
    } 
}


Mjordan2nd Dec 1st, 2005 6:02 PM

It only points to the original.

crawforddavid2006 Dec 1st, 2005 6:12 PM

Just for future reference you should NOT use newwhatever for an object name because it might get confused the reserved word in java 'new'. :D

Arevos Dec 1st, 2005 6:17 PM

Quote:

Originally Posted by crawforddavid2006
Just for future reference you should NOT use newwhatever for an object name because it might get confused the reserved word in java 'new'. :D

No it won't, and for the same reason I could have a variable called "for1" or "if2".

Writlaus Dec 1st, 2005 6:20 PM

Quote:

Originally Posted by crawforddavid2006
Just for future reference you should NOT use newwhatever for an object name because it might get confused the reserved word in java 'new'. :D

I think what he meant is that it would get confused by people, not the compiler. And I agree; I realized that after I typed it in--If that were actual code, I'd have changed that name.

Arevos Dec 1st, 2005 6:44 PM

Ohhhh, okay. I've been thinking about code too much recently :)


All times are GMT -5. The time now is 8:47 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC