为什么主要方法必须在Java类中?
主要方法是Java执行的入口点。当我们执行一个类时,JVM搜索main方法并逐行执行它的内容。
如果遵循以下示例,则可以编译该程序,但是如果尝试执行该程序,则会收到错误消息“找不到主方法”。
示例
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");
}
}输出结果
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
热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短