Java chapter Seventh Class and object notes
The characteristics of an object--the properties of a class each object has a specific value for each property
Operation of objects--Methods of classes
Second, the package: The object has both properties and methods two characteristics.
Object properties and methods are often encapsulated together to reflect the nature of things,
They are mutually reinforcing and cannot be divided.
Iii. differences between classes and objects:
Class: Abstract concept, is a mold that determines the properties and methods of an object.
Object: The kind that can be seen and touched. have static and dynamic characteristics.
Iv. steps to define a class:
1. Defining the class name
2. Define the class's property access Modifier Property Type property name = default value;
3. Define the method access modifier for the class return value type method name () {
Method body;
}
V. Member variables and local variables
Member variables: The ancestor is the class, the scope is the entire class
Local variables: The ancestor is the method, the scope is the current method
Six, class name naming rules:
1. Not using Java keywords
2. The first letter can be a letter, or it can be _ or $
3. Cannot contain spaces and punctuation
Vii. Creating objects: Keywords: new
Class Name Object name =new class name ();
Example: Yuntuschool beijing=new yuntuschool ();
Viii. use of objects: key symbols
The name of the object. Attribute = value; Beijing. Schoolname= "cloud-linked Beijing Center";
The name of the object. method; Example: Beijing.showinfo ();
Nine, the advantages of object-oriented:
1. Easy to program simulation of real-world entities
2. Hide details (encapsulation): The behavior and properties of an object are encapsulated in a class,
The outside world is obtained by invoking the methods of the class, without paying attention to how the internal details are implemented.
3. Reusable
You can create objects of multiple classes through the template of the class.
The class is the reference data type, when the value is passed, object 2 = Object 1, the address is passed, one change, and the other one is changed; object 2.name= Object 1.name
Java chapter Seventh Class and object notes