java 静态方法和静态变量java

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7815664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 21:32:24  来源:igfitidea点击:

static method and static variable java

javavariablesmethodsstatic

提问by user983246

Possible Duplicate:
static in the main class java and non static in constructor

可能的重复:
主类 java 中的静态和构造函数中的非静态

i just want to know if people can agree with me on the knowledge I have about static variable and methods as I'm still learning java in its early concepts.

我只是想知道人们是否能同意我关于静态变量和方法的知识,因为我仍在学习 Java 的早期概念。

static variables means when both objects or instances of the class gets shared the same variables. static methods simply means methods that refer to the class that it is written in.

静态变量意味着当类的对象或实例共享相同的变量时。静态方法仅表示引用它所写入的类的方法。

Anyone can correct me if I'm wrong or can add any more information are welcome as I want to be able to learn java to its fullest and do amazing things with java in the future! :)

如果我错了,任何人都可以纠正我,或者可以添加更多信息,因为我希望能够充分学习 Java,并在未来用 Java 做一些令人惊奇的事情!:)

Happy coding!

快乐编码!

回答by Pete Houston

Static variablesare shared for all instances of the class.

Static variables为类的所有实例共享。

Static methodsare accessed directly by class name, not belong to any instances.

Static methods直接通过类名访问,不属于任何实例。

回答by adatapost

You might want to read - Class Variables (Static Fields)and Class Methods.

您可能想阅读 -类变量(静态字段)类方法