What if the main() method is declared as private?

Description:

What happens when the static modifier is removed from the signature of the main() method?

Solution:

When the main() method is declared as private, the program compiles but during runtime it shows “main() method not public.” Message. When the static modifier is removed from the signature of the main() method, the Program compiles but at runtime throws an error “NoSuchMethodError”.

0 answers