Link Multiple Class


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Link Multiple Class

  1. #1
    Join Date
    May 2007
    Posts
    843

    Link Multiple Class

    Hello all expert Java programmer, i truly new to Java world.

    As you all know, main is inside a class.

    If i have three class, but i want to cal it from a single main. How can i do that ?

    This can be easy achieve in C++ but i have no idea in C++.

    Thanks.

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    You, the designer, decide which class will be your driver class - usually the one which builds the GUI and receives and delivers all input and output, dispatching messages to other classes which provide functionality which is your program's work

  3. #3
    Join Date
    May 2007
    Posts
    843
    I rougly can understand what u mentioned here bu can u provide some concrete example.

    Thanks for your help.

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Code:
    public class Driver
    {
        A myA;
        B myB;
    
        public void Driver ()
        {
              A myA = new A();
              B myB = new B();
           /// other construction stuff ///
        }
    
        public static void main( String [] args )
        {
               Driver myDriver = new Driver();
    
       ///// other stuff you want to do ///
        }
    
    }

  5. #5
    Join Date
    May 2007
    Posts
    843
    Does A and B class need main itself in its respective class ?

  6. #6
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    No. Just like C++, the only class that must have a method main is the class that is the entry point to your program.

    In Java, only the class which is coded by the .java file which is the file you compile when you call javac.exe needs to have a method main.

    However, it is not odd to have a method main in each class - it is a way to test the class - but those methods are not called when its class is referenced by another class which contains the entry point for your program - - - a/the constructor is called.

  7. #7
    Join Date
    May 2007
    Posts
    843
    Thanks for your help. Problem Solved.

Similar Threads

  1. Replies: 7
    Last Post: 03-17-2008, 11:18 AM
  2. copy common base class in C#
    By xja in forum .NET
    Replies: 0
    Last Post: 08-24-2006, 11:49 AM
  3. Help with class/applet
    By none_none in forum Java
    Replies: 17
    Last Post: 04-28-2005, 04:00 PM
  4. How To Do It - Shared Class Variables Part IV
    By Patrick Ireland in forum .NET
    Replies: 3
    Last Post: 05-07-2001, 04:04 PM
  5. Re: Doing Multiple Inheritance in java
    By Ali Imran in forum Java
    Replies: 0
    Last Post: 03-21-2000, 08:41 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
  •  
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