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
public"

Is This Answer Correct ?    92 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
exception.

Is This Answer Correct ?    14 Yes 4 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(){
System.out.println(x);
}
}
class Test
{
private static void main(String args[])
{
A a = new A();
a.show();
}
}

out put:-
Main method not public

Is This Answer Correct ?    7 Yes 1 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 / 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()

i.e.
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 the need of "creating and throwing an UserdefinedException" when the "Exception" class is already available?

4 Answers  


How to add two numbers with out using Arithmetic , union operators in java....? But we can use bitwise operators... but how...?

4 Answers   Satyam, CTS,


what is polymorhism what is inheritance? what is Abstract n Interface? what if two interfaces have same method and a concrete class is implementing both the interfaces. Will there be a compilation error? What are mutable and immutable classes? How can u make a class mutable? when will u use dem ...explain with example? what is overriding and overloading? what is garbage collection? what is Thread? how do dey communicate? what are the different ways of implementing ? have u used any messaging technologies? what is synchronization? what are some additions in java 1.5? what are generics? whst is advanced for loop? what is finally block? can u have a try in finally? yes!! can u have a finally in finally? how do you write junits? when is a object eligible for garbage collection?explain? a = null and b has ref to a will b be eligible to be garbage collected? sql questions like diff joins? how do dey work? exception handling? what is marker interface? what is the need??

0 Answers   JPMorgan Chase,


why use interface? if interface declear a method implement in class. why direct implement method in class

1 Answers   HCL,


JVM responsibility?

6 Answers   TCS,


what is the use of thread?Justify it by project point of view

7 Answers  


What is the difference between panel and frame ?

6 Answers   HCL, IBM, Raim Techno Solutions,


Hai all I want to print given array in reverse order Ex: int a[]={1,2,3,4,5};display this array in reverse order.

4 Answers  


What happens if an exception is not caught?

6 Answers  


What are different types of access modifiers?

3 Answers  


what is Inheritense

3 Answers   Tech Mahindra,


What happens to the Exception object after handling an exception?

0 Answers  




Categories