Object Naming

P

Paul Foreman

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?
 
J

Jim Sculley

Paul said:
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.
 
R

Roedy Green

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();
 
R

Roedy Green

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top