What happens if public static void main(){} is made protected?

Editorial / Best Answer

Answered by: Sushil Jain

  • Nov 21st, 2007


You will be able to compile but it will through a run time error saying "main method not public".

Showing Answers 1 - 48 of 48 Answers

ksatya

  • Nov 21st, 2007
 

Nothing happens. The code will run fine. you can have public/private/protected methods. main in one of the method if you make protected. But if you want to execute this as an application then you have to give public static void main.

Thanks,
KSatya

Sushil Jain

  • Nov 21st, 2007
 

You will be able to compile but it will through a run time error saying "main method not public".

satheesh kumar sriramaneni

  • Nov 22nd, 2007
 

We can able to compile that java file, means we can get the class file.
But we can't get the predicted value.

  Was this answer useful?  Yes

Prashant

  • Nov 23rd, 2007
 

If we made it private then its scope gets changed ie private and hence while runing any java program it will call main method first as becasue its scope is public and hence if it is private then the main would not gets called implicitly we have to call that explicitly

  Was this answer useful?  Yes

sid

  • Nov 26th, 2007
 

It gets compiled, but at run time it says that it is not public. Because JVM is not capable to access the static method of main class. Actully JVM is present out side of the class so access modifier is not allowed to do to access the main method.

  Was this answer useful?  Yes

prdeep

  • Dec 14th, 2007
 

It gets compiled, but at run time it says that it is not public. Because JVM is not capable to access the static method of main class. Actully JVM is present out side of the class so access modifier is not allowed to do to access the main method.

  Was this answer useful?  Yes

sampra

  • Feb 11th, 2008
 

Illegal combination of modifiers: public and protected
protected public static void main(String as[])

Error will come

  Was this answer useful?  Yes

AA

  • Apr 22nd, 2012
 

It will compile but gives error at run time......

  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