Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Object Naming

Reply
Thread Tools

Object Naming

 
 
Paul Foreman
Guest
Posts: n/a
 
      07-03-2004
Hi,
Just wondering if there is a way of naming the instance of a class from
a variable.

For instance instead of:
Person Paul = new Person(10);
Like:
int PersonName = P10;
Person PersonName = newPerson(10);

Any guidance please?



 
Reply With Quote
 
 
 
 
Jim Sculley
Guest
Posts: n/a
 
      07-03-2004
Paul Foreman wrote:
> Hi,
> Just wondering if there is a way of naming the instance of a class from
> a variable.
>
> For instance instead of:
> Person Paul = new Person(10);
> Like:
> int PersonName = P10;
> Person PersonName = newPerson(10);


No, you can't. Objects don't have names in Java.

>
> Any guidance please?
>


If you explain why you *think* you need such a thing, perhaps the
'proper' way to do it can be suggested.

Jim S.
--
Remove my extraneous mandibular appendages to reply via email.
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      07-03-2004
On Sat, 3 Jul 2004 09:36:13 +0000 (UTC), "Paul Foreman"
<(E-Mail Removed)> wrote or quoted :

>For instance instead of:
>Person Paul = new Person(10);
>Like:
>int PersonName = P10;
>Person PersonName = newPerson(10);
>
>Any guidance please?



int shoeSize = 10;
Person person = new Person( shoeSize );

or

Person.setDefaultShoeSize( 10 )
Person person = new Person();

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-03-2004
On Sat, 03 Jul 2004 08:35:07 -0400, Jim Sculley
<(E-Mail Removed)> wrote or quoted :

>No, you can't. Objects don't have names in Java.


You can declare a String field in a object which you assign a name,
but objects don't have names ordinarily. The closest thing you will
find is setName, setLabel and setText used in GUIs.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically naming an Object John Gearhart Ruby 1 10-09-2008 07:38 AM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
Javax.naming Exception: name not found in naming service. Harman Java 1 07-28-2006 08:51 AM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
RMI problem: Naming.unbind() but unused server object still living F C Java 0 03-03-2004 04:01 PM



Advertisments