简体   繁体   中英

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? 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; 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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