0

Can a class be made without having main () in it ?

please explain with example.

28th Nov 2016, 6:17 PM
Ravindra
Ravindra - avatar
2 Réponses
+ 4
Yes. In fact in a program you will have only one class containing a main() method. main() is the entry point to your program, i.e. the function called by the os to launch the program. In this example https://code.sololearn.com/c9w5m7TRBnc0/#java class A and B would normally be each one in its own file and called from a third one, Program, containing the main() method.
28th Nov 2016, 6:46 PM
Jean-Hugues de Raigniac
Jean-Hugues de Raigniac - avatar
+ 2
Of course you can create/write a class without main() But main() should be in anyone of the class in your application like this, class student { public string name; .... .... } class app { public static void main(....) { student obj = new student(); } } In this example, main() is in app class. Whereas we have create a new class student which doesn't have main(). Actually main() is the entry point to the application. Compiler starts executing the program from main(). So only one entry point should be there for every application. Hope you understand the concept.
28th Nov 2016, 6:46 PM
Venkatesh(Venki)
Venkatesh(Venki) - avatar