iTSCET

iT Portal

Can we declare multiple main() methods in multiple classes. ie can we have each main method in its class in our program?

Yes, We can have multiple main() methods in multiple classes. but if gives only single main method’s output depends upon our saving settings.

Ex::
class Maintest{
public static void main(String args[]){
System.out.println(“one”);
}
}
class Mt{
public static void main(String args[]){
System.out.println(“two”);}
}
public class Ma{
public static void main(String args[]){
System.out.println(“thr”);}
}

If we save with Maintest.java you will get “one” as output. if we save with Mt.java you will get “two” as output. like this it depends on your saving settings.If there is class contains Public as classname ,that must be saved as our classname.

Any how only one method must be executed.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: