What happens when a main method is declared as private?

Answers were Sorted based on User's Feedback

Answer / harsha

When a method is declared as private, the program compiles
properly but it will give runtime error ?Main method not

Is This Answer Correct ?    95 Yes 6 No

Answer / yogesh gandhi

Wrong Vani.

The output of the program is

C:\>javac abc.java

C:\>java abc
Main method not public.

Is This Answer Correct ?    66 Yes 4 No

Answer / amit kumar chaubey

If the main function is made private...it will compile
Sucessfully...and at the time of execution...it will
execute successfully...but desired result will not be
obtained. After execution..folowin message will be printed:
Main method not public.

Is This Answer Correct ?    21 Yes 1 No

Answer / srinivasa

JVM is also a program. If main() is declared as privateit
is not available outside of that class . So JVM through the

Is This Answer Correct ?    15 Yes 4 No

Answer / ashish

it compile easily... but it will give an error at the time
of execution .....

Is This Answer Correct ?    10 Yes 5 No

Answer / kundan

when u will declare main method is private
it will successfully compile and Run
and result will publish,

class A
int x=7;
void show(){
class Test
private static void main(String args[])
A a = new A();

out put:-
Main method not public

Is This Answer Correct ?    7 Yes 2 No

Answer / md parwez alam

does not have a main method

Is This Answer Correct ?    3 Yes 0 No

Answer / r.jainrocks@gmail.com

Byte that have main() implementation can become starting
point of program .

if a program have no main()

public static void main(String[] args)

properly it can't become starting point in application
it can be use through other program which capable to become
starting point.

Is This Answer Correct ?    3 Yes 1 No

Answer / subha narayan mohapatra

it will generate an error message because main() method is
the start or execution point in our java program.

Is This Answer Correct ?    4 Yes 2 No

Answer / sagar chavan

If the main function is made private,

we can do it but the starting point of project should be changed. By default it is main.

Is This Answer Correct ?    3 Yes 1 No

Post New Answer

More Core Java Interview Questions

What is meant by controls and types?

1 Answers  

Is ResultSet class?

5 Answers   TCS, Bally Technologies,

Any one can explain how the inerface uses in java. give with example.

1 Answers   IBM,

how can we use the servlet as standalone apllication?should we need to extend any class?

2 Answers   Logica CMG,

How to provide security in java

0 Answers   Tech Mahindra, Infosys, TCS,

What is an object?s lock? Give name of object?s that have locks?

2 Answers  

where to use join method and explain with real time senario?and programatical explenation also..

1 Answers   TCS,

Difference between JDK, JRE, JVM

16 Answers   TCS, Reliance, Deloitte, HCL, Oracle, Mind Tree, ThinkBox,

I/O blocking means?

1 Answers  

Which all r Final classes in java except string?

5 Answers   HCL,

We have two methods to create methods the threads. 1. Implementing runnable interface 2. Extending to thread class and overriding run method. Among these two which one is better and why? Please explain me in detail.

2 Answers  

What is the difference between panel and frame ?

6 Answers   HCL, IBM, Raim Techno Solutions,