could you run the java program without main method?
Answer Posted / shaik baji
Yes, we can execute the java program with out the main
method by using the the static block. After executing the
static block the JVM will search for the main method so to
skip this we should call System.exit(int) method.
NOTE: System.exit method contains integer parameter so we
shoud pass the integer value.
class MainDemo
{
static
{
System.out.println("hello i am visible without
main");
System.exit(0);
}
}
| Is This Answer Correct ? | 14 Yes | 4 No |
Post New Answer View All Answers
How many inner classes can a class have?
Explain about object oriented programming and its features?
What is unicode full form?
Can we define a package statement after the import statement in java?
Why can't you declare a class as protected?
What does the @override annotation do?
Is it possible to use string in the switch case?
What is the final keyword denotes?
Can we define static methods inside interface?
Describe different states of a thread.
What is an empty string in css?
Is vector ordered in java?
Write a program to calculate factorial in java?
How would overload a function based on return type?
Explain the hierarchy of java exception classes?