简体   繁体   English

Main 方法是如何使用的,它的目的是什么?

[英]how the Main method is used and what it's purpose is?

When using inheritance structure in java is the main method always in the last child(extended) class or should it be in the first parent class?在java中使用继承结构时,main方法总是在最后一个子(扩展)类中还是应该在第一个父类中? And what is the main purpose of this method?这种方法的主要目的是什么?

The main method is static, and thus can't be inherited, and so your title is wrong; main 方法是静态的,因此不能被继承,所以你的标题是错误的; you can't "extend" the main method.你不能“扩展”主要方法。

For many large projects that I've seen, it goes in its own class expressly built for the purpose, a class that is neither a "child" nor a "parent" class, other than being a child of the Object class.对于我见过的许多大型项目,它都包含在专门为此目的构建的自己的类中,该类既不是“子”类,也不是“父”类,而是 Object 类的子类。

Also understand that any class (or interface, enum,...), and multiple classes within a project, can have a main method, and sometimes this is used for testing purposes.还要了解项目中的任何类(或接口、枚举等)和多个类都可以有一个 main 方法,有时这用于测试目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM