Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 1st, 2005, 3:29 PM   #1
Writlaus
Hobbyist Programmer
 
Writlaus's Avatar
 
Join Date: Nov 2005
Posts: 149
Rep Power: 3 Writlaus is on a distinguished road
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?
Writlaus is offline   Reply With Quote
Old Dec 1st, 2005, 3:57 PM   #2
groovicus
Programmer
 
Join Date: Nov 2004
Posts: 84
Rep Power: 4 groovicus is on a distinguished road
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);
    }   
}
__________________
HijackThis Team-SFDC
groovicus is offline   Reply With Quote
Old Dec 1st, 2005, 5:02 PM   #3
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
It only points to the original.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Dec 1st, 2005, 5:12 PM   #4
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 579
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to 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'.
crawforddavid2006 is offline   Reply With Quote
Old Dec 1st, 2005, 5:17 PM   #5
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
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'.
No it won't, and for the same reason I could have a variable called "for1" or "if2".
Arevos is offline   Reply With Quote
Old Dec 1st, 2005, 5:20 PM   #6
Writlaus
Hobbyist Programmer
 
Writlaus's Avatar
 
Join Date: Nov 2005
Posts: 149
Rep Power: 3 Writlaus is on a distinguished road
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'.
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.
Writlaus is offline   Reply With Quote
Old Dec 1st, 2005, 5:44 PM   #7
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Ohhhh, okay. I've been thinking about code too much recently
Arevos is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:33 AM.

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