What happens when a main method is declared as private?
Answer Posted / sachin
JVM wants to execute the class its starting Execution from main Method means if JVM wants to execute main method if we declare main Method as private then its restriction the scope of main method if we declare Main Method as public then only jvm can applicable to access the main Method.
for e.g
class SE3
{
private static void main(String[] args)
{
System.out.prinln("Hello");
}
}
E:A_coreResearch_Programs>javac SE3.java
E:A_coreResearch_Programs>java SE3
Error: Main method not found in class SE3, please define the main method as
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Which programming language is best in future?
What is difference between static and final?
What is toarray method in java?
Does constructor creates the object ?
What are the different ways of implementing thread? Which one is more advantageous?
Can we write method inside a method in java?
What is meant by object oriented programming – oop?
What is java util collection?
What is the final keyword denotes?
How does multithreading take place on a computer with a single cpu?
What are the main uses of java?
What is collection class in java? List down its methods and interfaces.
Is a string literal?
Can we sort array in java?
enlist some features of jdk.