Java basics: 28th member variables

Source: Internet
Author: User

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

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.