- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Why the main method has to be in a java class?
Main method is the entry point of the execution in Java. When we execute a class JVM searches for the main method and execute the contents of it line by line.
If you observe the following example you can compile a this program but if you try to execute it you will get an error saying “Main method not found”.
Example
abstract class SuperTest { public abstract void sample(); public abstract void demo(); } public class Example extends SuperTest{ public void sample(){ System.out.println("sample method of the Example class"); } public void demo(){ System.out.println("demo method of the Example class"); } }
Output
C:\Sample>javac Example.java C:\Sample>java Example Error: Main method not found in class Example, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application
- Related Articles
- Why "this" keyword cannot be used in the main method of java class?
- Why main() method must be static in java?
- Why the main () method in Java is always static?
- Class declaration with a method that has a parameter in Java
- Can the main method in Java return a value?
- Why is the Main() method use in C# static?
- Why final variable doesn't require initialization in main method in java?
- Is main method compulsory in Java?
- Can we override the main method in java?
- Can we overload the main method in Java?
- How to execute a static block without main method in Java?
- Does JVM creates object of Main class in Java?
- Override the toString() method in a Java Class
- Can we overload Java main method?
- Why can't a Java class be both abstract and final?

Advertisements