Is the following Java program run? private static void main(String args[]) { class valan { //body of the class } }

No. Compilation error will occur.

The error message is : main method should be public

Questions by valanarasu   answers by valanarasu

Showing Answers 1 - 20 of 20 Answers

manoj

  • Oct 9th, 2006
 

main method shuld be in public

  Was this answer useful?  Yes

amitjain

  • Oct 17th, 2006
 

No,it'll not run and it gives compile time error,because main() method is called by JVM(Java Virtual Machine) i.e. outside from ur program unit.so it must be public.

  Was this answer useful?  Yes

Guest

  • Dec 8th, 2006
 

It wont compile because of the following two reasons.

1> First the signature of the main method is wrong. The main method must be public.

2> Secondly the main method must be inside some class. In Java a method cannot persist by itself. It must be a member of some class.

  Was this answer useful?  Yes

Guest

  • Jan 22nd, 2007
 

No.... a class keyword is the super of all java programs, so it should start with an external class, and a program to standalone it should have main method inside the superclass class keyword followed by a class name.

  Was this answer useful?  Yes

ven_v2

  • Jan 29th, 2007
 

This program will not run. It wil give u a compiletime error called - ( 'class' or 'interface' expectedprivate static void main(String args[]) ).

  Was this answer useful?  Yes

dile_sahoo

  • Mar 4th, 2007
 

On compile time it will not give any error,because all syntax are correct, but at Run-time it gives an Error like "main method is not public".because jvm acess the main method by outside of the classes so it should be public.

  Was this answer useful?  Yes

Jignesh

  • Mar 25th, 2007
 

No it won't creat any compile time and Run time exception..... and also it is possible to add Inner class at Method Level.

  Was this answer useful?  Yes

Ashok Agnihotri

  • Nov 19th, 2007
 

NO, it will not run because main is private and it should be public in order to run this code.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions