Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
The main() method is mandatory for the class's or application's execution. You may though define multiple main() methods in classes of the same package with no problems.
For a java program only one main() method is required that should be in the source class. that method can be called by any classes defined in the program without object .the main method is independent of objects.
for ex:
class Test()
{
public static void main(String args[])
{
Add ob= new Add();
System.out.println("Result =" +ob.Sum());
}
}
public class Add
{
int a= 2,b= 3,c=0;
public int Sum()
{
c=a+b;
return c;
}
}
here Test is the source class that requires main() method remaining classes not required that main() method. when execution starts source class will call other classes.
There is only one Main method you should call to perform your program. Other classes may performed in a calling function inside Main().