简体   繁体   English

main()是一个类方法吗? (JAVA)

[英]Is main() a class method? (Java)

Saw a question which detailed a simple class. 看到一个详细介绍一个简单类的问题。 The class had a basic (and non-static) method. 该类有一个基本(和非静态)方法。 It also had a main method. 它还有一个主要方法。

The question asked: does this class have a class method? 问的问题是:这个班级有一个班级方法吗?

Can public static void main(String[] args){} be considered a class method? public static void main(String[] args){}可以被认为是一个类方法吗?

Yes, 是,

All static methods are called Class method, because, they belong to the Class, not to any instances of that Class. 所有静态方法都称为Class方法,因为它们属于Class,而不属于该Class的任何实例。

So public static void main(String[] args){} also a Class method 所以public static void main(String[] args){}也是一个Class方法

Not only main() method, every static member is belongs to Class which can be shared across all the instance and not to any specific instance. 不仅main()方法,每个静态成员都属于Class ,它可以在所有实例之间共享,而不是任何特定实例。

Static members bound to Class. 静态成员绑定到Class。 So you can consider that as a class method. 所以你可以把它看作一个类方法。

Prefer to read : Understanding Class Members 更喜欢阅读: Understanding Class Members

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

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