A member variable is used to describe an object. It can be a variable of the basic data type or an object of other types. For example:
Public class person {
Int age; // member variable of the basic type
Date birthday; // other types of objects as members
}
The variable name must comply with the naming rules of the flag. For more information, see the previous section. In terms of programming habits, the first letter is lowercase, a variable consisting of multiple words, and the first letter of other words is capitalized.
According to the object-oriented encapsulation feature, member variables are usually private and can be accessed through public methods. For example:
Public class person {
Private int age; // member variable of the basic type
Private date birthday; // other types of objects as members
}
In addition to the preceding two access controllers (default and private), the access controllers include public and protected. The introduction of public in the benefit and access sections of objects, and the introduction of protected in the inheritance section.
In addition to access control operators, member variables can also have the following modifiers:
Static, which is described in the static member, static method, and static initiator sections;
Final indicates that the current variable is unchangeable, that is, a constant. The usage of this variable is described in the usage section of the object.
Last time:
27th class definitionNext time:
29th member MethodsLi xucheng csdn blog: Why? U= 124362 & C = 7be8ba2b6f3b6cc5