Instantiating a new Object


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Instantiating a new Object

  1. #1
    Join Date
    Oct 2004
    Posts
    9

    Smile Instantiating a new Object

    I was wondering... If you have a main function in a class, and then have functions in that class that instantiate a new structure defined in another class, can you work on the new structure while you're in main? Here's an example I've compressed to show what I'm trying to do:

    Code:
    import java.io*;
    import java.lang*;
    import java.util*;
    
    public class ossim{
       public static int main(String args[]){
          functionCaller();
    
          /* Can you now work on the new PCB "hello" structure here */
          /* such as setting hello.PID = 1 ? */
    
          return 0;
       }
    
       public static void functionCaller(){   /* instantiate PCB */
          PCB hello = new PCB();
       }
    }
    
    class PCB{
      int PID;        /* process id number */
      int priority;   /* priority of process */
      String statusType;
      LinkedList statusList = new LinkedList();
      int[] crTree = new int[10];
      LinkedList otherResources = new LinkedList();
    }
    Any suggestions?

  2. #2
    Join Date
    Feb 2005
    Posts
    3
    Hi,

    You cannot do that. Just because the life of the Class object you have created will die after the block it exists is finished.

    So, you cannot do that. But in case, if you delcared an object inside main, you can do like that.

    Is that ok?

    Ram
    Ram

  3. #3
    Join Date
    Oct 2004
    Posts
    9
    Thanks

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