ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Can we have more than one main method in a class?

user-image
تم إضافة السؤال من قبل mahesh sharma , Software Developer , Tech Mahindra
تاريخ النشر: 2013/11/30
Anas Rabei Abd ALLAH
من قبل Anas Rabei Abd ALLAH , Senior Software Developer , The Center Of Strategic Studies

The answer is depending on what you want. 

 

If you want more than one main method with the same signature, the answer will not NO and this is not for the main method only, it is the same for any other method.

 

If you want just the name of the method, the answer will be YES. Simply you can overload the main method as nothing special to it.

 

The only fact that you should put in mind is that when the compiler start to run your application, it will search for the method with the following signature (public static void main(String[])) in the specified startup class.

yes, u can have more then one main method in a class just maintion the main method public which u  want to start the jvm execution.

مستخدم محذوف‎
من قبل مستخدم محذوف‎

we can have have multiple main methods, but in that one main method must be PSVMain(String args[]) and others different from this.

Cedric Nabaa
من قبل Cedric Nabaa , Java developer , Capital Banking Solutions

You cannot have morethan one main method in a class. The main method is like any other methods, You cannot have in java the same method (same signature: return type, method name, number/type of parameters) declared twice in a class

Pawan Kumar
من قبل Pawan Kumar

Yes,you can have more classes that contain the main() method, but at least one class which should contain main() and it should be public so that JVM will start that class as Main thread during compilation

مستخدم محذوف‎
من قبل مستخدم محذوف‎

no.more than one main method can't be used in class of same .

VIJAY PRASAD
من قبل VIJAY PRASAD

NO THERE MUST BE A SINGLE MAIN METHOD IN YOUR CLASS..MAIN() IS ENTRY POINT OF OUR PROGRAM.MAIN FUNCTION CAN BE EITHER VALUE RETURNING OR NON VALUE RETURNING.

Preetham D
من قبل Preetham D , Software Engineer / Senior Software Engineer , Mindtree

Class can contain may functions, but you can have only one main function

مستخدم محذوف‎
من قبل مستخدم محذوف‎

only one main method

Manish Gour
من قبل Manish Gour

yes but the main with array of string is considered as main thread so this cant be override and apart from that we can have any no. of main methods

Ajith Fernandez
من قبل Ajith Fernandez , Software Engineer , Nayasoft Solutions Pvt.ltd

No the program fails to compile. The compiler says that the main method is already defined in the class.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟