What are the domains in Java?

Source: Internet
Author: User

Polymorphism is a special problem in the domain. I can not understand the Chinese version of the book directly called the domain, read the original English, the original writing is fields, direct translation Although correct, but the problem of the variable is not a domain. Specifically checked what's the meaning of field in Java? Many people think of it as a range enclosed in curly braces.


and find this post.

What's a field in Java?


A field is an attribute. A field may is a class ' s variable, an object's variable, an object ' s method ' s variable, or a parameter of a function.

Class bike{   static int bikes;  int gear;  int cadence;  void Create (int newgear, int newcadence) {    bikes = bikes + 1;    Gear = Newgear;    Cadence = newcadence;}  int GetSpeed () {    int speed = gear*cadence*5*3.141;    return speed;  }}

' Bikes ' is a class ' s variable (class variable) (static field).
The ' gear ' and ' cadence ' could is an object's variables (instance variables) (non-static fields).
' Speed ' was an object ' s method ' s variable (local variable).
' Newgear ' and ' newcadence ' are parameters of a function (parameters).


field, a field is a property that can be a class variable, an object variable, an object method variable, or a parameter to a function. (Supplemental, class's variables, instance variables and static variables of classes are called class ' s variables, generic variables, also known as class variables or data fields, actually translated into properties can also, class properties, sounds not weird, from Baidu Encyclopedia).


Class bike{   static int bikes;  int gear;  int cadence;  void Create (int newgear, int newcadence) {    bikes = bikes + 1;    Gear = Newgear;    Cadence = newcadence;}  int GetSpeed () {    int speed = gear*cadence*5*3.141;    return speed;  }}


Bikes is a class variable (static field).

Gear and Cadence are object variables (instance variables) (non-static domains).

(Here is a little bit of a contradiction, in fact, according to the encyclopedia, so bikes, gear and cadence are class variables, bikes is a static variable in the class variable, and gear and cadence are the instance variables in the class variable.) )


Speed is the variable (local variable) of the object method.

(see no, local Variable,java does not appear gobal variable, global variables, to say that the scope of the class variable is the same as the global variable, but not called).


Newgear and Newcadence are parameters (parameters) of a function (method).




Original address: Http://www.answers.com/Q/What_is_a_field_in_java

What are the domains in Java?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.