I declared main() method as private. But it still running
and displaying the output. Please Answer it .
Code Snippet as Below:
import java.io.*;

class over
{
private static void main(String[] args)
{
int high = Integer.MAX_VALUE;
int overflow = high + 1;

int low = Integer.MIN_VALUE;
int underflow = low - 1;

System.out.println(high + "\n" +overflow +"\n"+
low +"\n"+underflow);
//System.out.println(overflow);
//System.out.println(low);
//System.out.println(underflow);
}
}

Answers were Sorted based on User's Feedback



I declared main() method as private. But it still running and displaying the output. Please Answer..

Answer / kumaresan.r

Hai,
When you compile program it will run with out error,bt it
did not show the value of high,low,underflow.it just show that

"Main method not public.

Process completed.".

So we cant say that this is an output.

Is This Answer Correct ?    15 Yes 0 No

I declared main() method as private. But it still running and displaying the output. Please Answer..

Answer / surendar

hi, Pranav Kumar.
"MAIN METHOD NOT PUBLIC" it isn't output.
When u compile the programe, compiler checks only the syntax errors, variable defination, method prototype etc.
So here compiler doesn't check method prototype weather method
is public or private.
But JVM checks, so to be called by the JVM that method must be public.

Is This Answer Correct ?    9 Yes 0 No

I declared main() method as private. But it still running and displaying the output. Please Answer..

Answer / ravi ranjan

OUTPUT = NO SUCH A METHOD EXCEPTION
REGION= MAIN METHOD MUST BE PUBLIC BECAUSE IT CALLED BY THE
DEMON THREAD

Is This Answer Correct ?    1 Yes 0 No

I declared main() method as private. But it still running and displaying the output. Please Answer..

Answer / bhavya

Since main method is made private JVM does not find the main class, so it says there is no main method.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Core Java Interview Questions

Why do we use bufferedreader?

0 Answers  


why should we get the following error ? Exception in main method NoClassDefFoundError:classname could anyone give the detail clarification on how java compiler can look for .class file?

2 Answers  


Explain about fail fast iterators in java?

0 Answers  


What is a superclass?

0 Answers  


How to declare unique ArrayList ?

6 Answers   RMSI,


How can we create a synchronized collection from given collection?

0 Answers  


How does access modifiers work?

1 Answers   Wipro,


How to sort array of 0 and 1 in java?

0 Answers  


What is boolean example?

0 Answers  


If a variable is declared as private, where may the variable be accessed?

0 Answers  


What is a buffer in computer?

0 Answers  


Is it compulsory for a try block to be followed by a catch block in java for exception handling?

0 Answers  


Categories