creating varible names from varibles


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: creating varible names from varibles

  1. #1
    Join Date
    Jan 2004
    Posts
    10

    creating varible names from varibles

    Ok I would like to create some variable names from other variables, but I donít seem to be able to get this to work, I have tried a couple of ideas. Is it possible to do this?

    What I would like is that, I could increment the name of a variable so I can create variables with different names.

    Please help.


    1.
    Code:
    int increment = 0; 
    SubClient clientobject+increment = new SubClient(firstname,lastname,tphone,address);
    Code:
    Error 1
    reportprogram.java:245: ';' expected
    SubClient variablename + increment = new SubClient(firstname,lastname,tphone,ad
    ress);
                           ^
    1 error
    2.
    Code:
    int increment = 0; 
    String newvariablename = "clientobject"+increment ;
    SubClient newvariablename = new SubClient(firstname,lastname,tphone,address);
    Code:
    Error 2
    reportprogram.java:245: variablename is already defined in methreadDataIntoDest
    nation(java.lang.String)
    SubClient variablename = new SubClient(firstname,lastname,tphone,address);
    
              ^
    1 error

  2. #2
    Join Date
    Jan 2004
    Posts
    8
    Hi,
    Problem 1
    To solve problem 1 you would have to use an array of objects.

    Problem 2
    In this you are trying to give two object variables the same identifier.
    You have created a String object called new variable name, you then attempt to create an object reference of type SubClient with the same identifier.
    You cannot have two variables, be they object identifiers or references to simple data types, of the same name.

    PS
    if you really do get stuck, e-mail me and I will try to sort it out
    ashley.hu1me@virgin.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center