Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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

user-image
Question ajoutée par Ayushi Bansal , Intern , Wipro Infotech Ltd.
Date de publication: 2014/07/06
geeta sethi
par geeta sethi , faculty , apar india college

No, we can use one main function in a program

Utilisateur supprimé
par Utilisateur supprimé

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
par 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
par 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
par 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..

More Questions Like This