Results 1 to 2 of 2

Thread: mutiple object

  1. #1
    ahmed80 is offline Member
    Join Date
    Jan 2011
    Rep Power

    Default mutiple object

    i want to creat a multiple object for receiver class then pass this object R1 to other constructor of classes.i have confusion that other constructor add in this loop or outside the loop. .
    using this code:

    Receiver[] R1=new Receiver[4];
    for(int i=1;i<=3;i++)
    R1[i]=new Receiver(Que1,tid1,rRandom1,"Receiver",i);
    Channel ch1 = new Channel(waitQue1, q1, RTT1,FieldSize1,tid1,R1,chRandom1,i);

    is this code generate 3 times ch1 or only one time.

    hope some body help me.

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Rep Power


    it will generate a ch1 each and every time the for loop is invoked.
    in this case since ch1 is declared inside the for loop, the next iteration of the loop the reference to it will be lost, and it will be garbage collected.. unless there is a refence to this from somewhere else. e.g. if there was a list of these outside of the array,

Similar Threads

  1. Storing Mutiple Classes/Data Types in a Linked List
    By Chronoattica in forum New To Java
    Replies: 7
    Last Post: 12-28-2010, 11:03 PM
  2. issue of mutiple panels
    By de.megha in forum AWT / Swing
    Replies: 1
    Last Post: 07-26-2010, 09:27 AM
  3. Replies: 2
    Last Post: 06-22-2010, 04:29 AM
  4. Replies: 0
    Last Post: 03-24-2010, 11:39 AM
  5. Replies: 1
    Last Post: 03-04-2009, 07:14 PM

Posting Permissions

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