DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links