Java 中的字段。字段和方法的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20668014/
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
Fields in Java. Difference between Field and Method
提问by Bala Subramanyam
What is meant by Field in Java? I have Googled about this, I got some answers but I couldn't understand. What is the difference between Field and Method. Is enum associated with field in java? I find _ACTIVE, _DISCARDING, _HOLDING and many as fields in java.
Java中的字段是什么意思?我在谷歌上搜索过这个,我得到了一些答案,但我无法理解。字段和方法有什么区别。枚举与java中的字段相关联吗?我在 java 中找到了 _ACTIVE、_DISCARDING、_HOLDING 和许多字段。
采纳答案by user1445967
A field is a member variable that belongs to a class.
字段是属于类的成员变量。
A method is a set of java commands referred to by name. You are able to execute all the commands by using the name of the method. Methods can take values as parameters and return a value as a result.
方法是一组按名称引用的 java 命令。您可以通过使用方法的名称来执行所有命令。方法可以将值作为参数并作为结果返回值。
An Enum is a special datatype somewhere between a regular primitive datatype and a class.
枚举是介于常规原始数据类型和类之间的特殊数据类型。
And you should definitely read the tutorial on what a class is.
你绝对应该阅读关于什么是类的教程。
回答by Mitesh Pathak
Member :Normally used to define the variables and methods.
Attribute :Attributes are the instance variables of an Object.
Variable :Primitive variables and Objects reference variables as instance or local variables.
Field :Field marks an instance variable.
Method :Function defined in class
Member:通常用于定义变量和方法。
属性:属性是对象的实例变量。
变量:原始变量和对象引用变量作为实例或局部变量。
字段:字段标记实例变量。
方法:在类中定义的函数