JAVA basics/Lesson 7: Object-oriented/JAVA class attributes, class variables and instance variables, Object-Oriented java

Source: Internet
Author: User

JAVA basics/Lesson 7: Object-oriented/JAVA class attributes, class variables and instance variables, Object-Oriented java

2013-06 6

1. attribute type

The attribute type can be a basic type, such as an Int integer or a float floating point number, such as a String.

2. attribute name

Attribute names are generally in lower case, such as name
If there are multiple words, the first letter of the next word is capitalized, such as moveSpeed
Attributes are also variables, so the naming rules of variables must be met.

 

Class variables:Is a member variable in the class with the static Modifier

Instance variables:Class member variables that do not use static as modifiers

Class Student {int a; // instance variable static int B; // Class variable}

Features:

1. class objects share class variables. instance variables are private class variables of each class and can be accessed by class name, class variable name, Object Name, and class variable name;

2. instance variables can only be accessed through the object name. instance variable name;

 

Final variable (constant ):

In a class, variables that use final as modifiers are called constants.

Final int MAX = 99;

Features:

1. All letters of the constant name must be capitalized;

2. Constant Declaration must be initialized;

3. A constant can only be accessed by an object but cannot change its value.

 

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.