- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Can we declare a main method as private in Java?
Yes, we can declare the main method as private in Java.
It compiles successfully without any errors but at the runtime, it says that the main method is not public.
Example:
class PrivateMainMethod { private static void main(String args[]){ System.out.println("Welcome to Tutorials Point"); } }
The above code is working successfully at compile time but it will throw an error at the runtime.
Output:
Error: Main method not found in class PrivateMainMethod, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application
Advertisements