What happens when a main method is declared as private?

Answers were Sorted based on User's Feedback



What happens when a main method is declared as private?..

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 ?    111 Yes 8 No

What happens when a main method is declared as private?..

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 ?    72 Yes 5 No

What happens when a main method is declared as private?..

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 ?    25 Yes 3 No

What happens when a main method is declared as private?..

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 ?    15 Yes 5 No

What happens when a main method is declared as private?..

Answer / ashish

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

Is This Answer Correct ?    12 Yes 5 No

What happens when a main method is declared as private?..

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 4 No

What happens when a main method is declared as private?..

Answer / md parwez alam

does not have a main method

Is This Answer Correct ?    3 Yes 0 No

What happens when a main method is declared as private?..

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

What happens when a main method is declared as private?..

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

What happens when a main method is declared as private?..

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 do you mean by pointer value and address?

0 Answers   Syntel, Visa,


how to crate clint-server socket?

1 Answers   Accenture, Infosys, Infotech, TCS,


What is empty string literal in java?

0 Answers  


Name two subclasses of the TextComponent class?

2 Answers  


Name and explain the types of ways which are used to pass arguments in any function in java.

0 Answers  






How do you detect memory leaks?

0 Answers  


What is strings in java?

0 Answers  


Does java have a compiler?

0 Answers  


What is double checked locking in singleton?

0 Answers  


What is a stream? what are the different types and classes of Streams?

2 Answers  


How is a variable stored in memory?

0 Answers  


Does unicode support all languages?

0 Answers  


Categories