刚开始学习Java。为什么main()在一个类中? [英] Just started learning Java. Why is the main() inside of a class?

查看:116
本文介绍了刚开始学习Java。为什么main()在一个类中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Java,我注意到 main()被放在一个类中。为什么?我不认为我的 main()是任何对象的成员。所以请告诉我如何解决这个问题。

I'm learning Java and I noticed that the main() is put inside of a class. Why? I don't consider my main() to be a member of any object. So please tell me how I can get around this.

推荐答案


我不认为我的 main()成为任何对象的成员。

I don't consider my main() to be a member of any object.

它不是因为它是 static 方法。它不属于任何对象,而属于类本身。

It's not since it's a static method. It does not belong to any object but to the class itself.

除此之外,所有方法,包括 main 必须在类中定义。

Aside from that, all methods, including main must be defined in classes.

更一般地说,类是编译的Java代码中的最小单元,包含有关类实例的信息自行运行的行为代码(例如 main 方法)。

More generally, a class is the smallest unit in compiled Java code and contains both information on instances of the class and behavioral code that runs by itself (e.g. the main method).

这篇关于刚开始学习Java。为什么main()在一个类中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆