Results 1 to 4 of 4
  1. #1
    bugger is offline Senior Member
    Join Date
    Nov 2007
    Posts
    111
    Rep Power
    0

    Default Creating abjects with different names

    Hi

    I want to create objects of different names. Please check the code below:

    Java Code:
    for(int i=0;i<noOfObject;i++)
    {
    	System.out.println("Obj Created " + i);
    	Student (obj+i) = new Student();
    }
    I get following error :(

    Java Code:
    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    	The left-hand side of an assignment must be a variable
    Any solution to this :confused:

  2. #2
    m_srikanth is offline Member
    Join Date
    Nov 2007
    Posts
    8
    Rep Power
    0

    Default

    You cannot use (obj+i) to assign an new object. Try using array of objects instead. Something like :

    obj[i] = new Student();

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  4. #4
    bugger is offline Senior Member
    Join Date
    Nov 2007
    Posts
    111
    Rep Power
    0

    Default

    Ok. So I cannot simply make objects of different name. I have to use Array, ArrayList or Vector to store somewhere.

    thanks.

Similar Threads

  1. Names pipes in java
    By Zept in forum Networking
    Replies: 2
    Last Post: 08-06-2011, 08:20 PM
  2. Getting method names using Reflection
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-24-2008, 03:18 PM
  3. Getting names of table columns
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-07-2008, 08:39 AM
  4. Drive names
    By alwz_nikhil in forum New To Java
    Replies: 0
    Last Post: 11-28-2007, 10:04 AM
  5. how to get the names of the files
    By mary in forum Advanced Java
    Replies: 2
    Last Post: 08-05-2007, 04:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •