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

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

متابعة

Can we use more than 1 main in 1 java program? Justify?

user-image
تم إضافة السؤال من قبل Ayushi Bansal , Intern , Wipro Infotech Ltd.
تاريخ النشر: 2014/07/06
geeta sethi
من قبل geeta sethi , faculty , apar india college

No, we can use one main function in a program

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

Yes, We can But Only One Main will be executed

You can't run the2 mains in the same time!!!!!

exp:

# Define case1

.........

# ifdef case1

int main()//main1

#else

int main() //main2

#endif

Ragavendran Viswanathan
من قبل Ragavendran Viswanathan , Senior Software Engineer , Ness Software Services Pvt,Ltd.,

Hi,

No, we cant use more than1 main method in a class because compiler first look for main method to compile and start progam invocation. If two main method persists then it will throw error "Main Method is Already exists"

Mohammed Ameen
من قبل Mohammed Ameen , Java Developer , TATA Consultancy Services Limited (TCSL)

No.

EXPLANATATION:

1)The Program fails to compile.The compiler says that main method is already defined in the class.

2)But it is possible to OVERLOAD the main method.

Md Maaz Akhtar
من قبل Md Maaz Akhtar , software engineer , Zrusti Technology Private Ltd

No we can't use more than1 main in java..because main method  is use to print..

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

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