Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

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

user-image
Question added by Ayushi Bansal , Intern , Wipro Infotech Ltd.
Date Posted: 2014/07/06
geeta sethi
by geeta sethi , faculty , apar india college

No, we can use one main function in a program

Deleted user
by Deleted user

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
by 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
by 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
by 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

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.