answersLogoWhite

0

It doesn't really make sense. The JVM needs to know where to start running the program; that's what the "main" method is for. A class - one that can be run directly - needs to have a single entry point, to avoid ambiguity. This main method can then call any number of other methods.

I assume you can call a second method "main", but using a different signature. However, to avoid confusion, I would recommend you don't do this.

User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Engineering

How nesting of methods is done in java?

No, Java only allows a method to be defined within a class, not within another method.


When do you declare a method final in java?

You declare a method final in Java when you do not want any subclasses of your class to be able to override the method. I have also heard that this allows the Java compiler to make more intelligent decisions. For example, it supposedly allows Java to decide when to make a method inline. (Note that this is all unconfirmed)


When do you declare a method or class abstract in java?

when overriding of a class or a method is necessary, they can be declared as abstract


How many values can a method return in Java?

A method in java can declare only one return value and type at a time. For ex: a single method cannot have a code that returns a string in some cases and an integer in other cases. Java compiler does not let you do that. You can only have one return type for every method in java.


How to write java program without using main method?

Java program without mainWe need a main method for executing a program.But YES we can write a program without using main() method.TRICK 1 of 2 :: while writing applets in java we don't use main... we use init() method instead.TRICK 2 of 2 :: using 'static' we can write a program whic will execute successfully and output the desired message on screen. Here it is :: class Mohit{ static { System.out.println("This java program has run without the main method"); System.exit(0); } } -->save the program as Mohit.java to compile::javac Mohit.java (in command prompt) to run ::java Mohit(command prompt) output will be ::This java program has run without the main methodWhoa!!!!! we are done.;)

Related Questions

How nesting of methods is done in java?

No, Java only allows a method to be defined within a class, not within another method.


When do you declare a method final in java?

You declare a method final in Java when you do not want any subclasses of your class to be able to override the method. I have also heard that this allows the Java compiler to make more intelligent decisions. For example, it supposedly allows Java to decide when to make a method inline. (Note that this is all unconfirmed)


When do you declare a method or class abstract in java?

when overriding of a class or a method is necessary, they can be declared as abstract


How many values can a method return in Java?

A method in java can declare only one return value and type at a time. For ex: a single method cannot have a code that returns a string in some cases and an integer in other cases. Java compiler does not let you do that. You can only have one return type for every method in java.


What will happen if a Java Class has no Main Method?

Nothing will happen. There is no restriction that every Java class must have a main method. The only program is that, this class cannot be executed as a standalone java program.


How to write java program without using main method?

Java program without mainWe need a main method for executing a program.But YES we can write a program without using main() method.TRICK 1 of 2 :: while writing applets in java we don't use main... we use init() method instead.TRICK 2 of 2 :: using 'static' we can write a program whic will execute successfully and output the desired message on screen. Here it is :: class Mohit{ static { System.out.println("This java program has run without the main method"); System.exit(0); } } -->save the program as Mohit.java to compile::javac Mohit.java (in command prompt) to run ::java Mohit(command prompt) output will be ::This java program has run without the main methodWhoa!!!!! we are done.;)


What is the executable method in java?

In Java, the executable method is the main method, which serves as the entry point for any standalone Java application. It is defined as public static void main(String[] args), where String[] args allows for command-line arguments to be passed to the program. The main method must be declared as public and static, and it returns no value (void). When a Java program is run, the Java Virtual Machine (JVM) looks for this method to start the execution of the program.


What is out of scope in returning objects in java?

if u declare variable in method & tray to use this variable outside the method then it is out of scope


Why java program is not running without the IOException declaration in main method?

Most likely, one of the methods you're calling is throwing an IOException. You either need to declare it to be thrown in the main method or surround the statement with a try-catch block.


Can you run java program without applying main method?

yes we can run java program without using main. we can run program by declaring the variable static..


Why main is used in java?

In java need main() method. without main() in java we won't run the java programe main() signals the entry point to the program - it tells the Java Virtual Machine which is the first program that should be executed.


Program for length of list in java?

Java's List interface defines the size() method, which can be used to retrieve the length of a list.