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++.
02-27-2008, 09:17 PM
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
03-06-2008, 07:53 PM
I rougly can understand what u mentioned here bu can u provide some concrete example.
Thanks for your help.
03-06-2008, 08:13 PM
public class Driver
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 ///
03-21-2008, 01:06 AM
Does A and B class need main itself in its respective class ?
03-21-2008, 07:17 AM
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.