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.