Can you declared constructor as private?

1 answer

Answer

1045809

2026-07-24 15:10

+ Follow

Java
Java

If you declare the main method anything other than public, it will not run.

If you declare main method as private, you would not be able to execute the class as a standalone Java program. Any Java class that needs to be executed as a standalone file needs to have a main method that is public, static and returns a void. Otherwise the Java compiler would not recognize the file as an executable standalone Java file and would not allow you to run it.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.