Object Naming

Discussion in 'Java' started by Paul Foreman, Jul 3, 2004.

  1. Paul Foreman

    Paul Foreman Guest

    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?
     
    Paul Foreman, Jul 3, 2004
    #1
    1. Advertising

  2. Paul Foreman

    Jim Sculley Guest

    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.
     
    Jim Sculley, Jul 3, 2004
    #2
    1. Advertising

  3. Paul Foreman

    Roedy Green Guest

    On Sat, 3 Jul 2004 09:36:13 +0000 (UTC), "Paul Foreman"
    <> 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.
     
    Roedy Green, Jul 3, 2004
    #3
  4. Paul Foreman

    Roedy Green Guest

    On Sat, 03 Jul 2004 08:35:07 -0400, Jim Sculley
    <> 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.
     
    Roedy Green, Jul 3, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. C

    Strong Naming

    C, Nov 5, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    408
    Steve C. Orr [MVP, MCSD]
    Nov 6, 2003
  2. F C
    Replies:
    0
    Views:
    2,233
  3. Harman
    Replies:
    1
    Views:
    2,512
    Moiristo
    Jul 28, 2006
  4. John Gearhart

    Dynamically naming an Object

    John Gearhart, Oct 9, 2008, in forum: Ruby
    Replies:
    1
    Views:
    101
    Robert Klemme
    Oct 9, 2008
  5. Cylix

    Naming problem on array object

    Cylix, Jul 3, 2006, in forum: Javascript
    Replies:
    14
    Views:
    199
    Laurent Bugnion
    Jul 5, 2006
Loading...

Share This Page