Object-oriented three main lines:
1. Composition of classes and classes
2. Object-oriented three main features: encapsulation, inheritance, polymorphism
3. Other keywords: This super Import package abstract static final interface etc.
The 1.java program is focused on the design of the class. Class from the point of view of the code: tie Relations! From the angle of execution, design: Association, inheritance, aggregation relationship
Class a{
}
Class b{
A = new A ();
}
2. Composition of Class: Attribute method constructor code block inner class
2.1 Properties: ① Variable classification: member variable (attribute Field) vs local variable (parameter of method, inside method, inside code block)
Basic data types (8, different data types correspond to different default initialization values) vs reference data types (arrays, classes, interfaces default initialization values are NULL)
Declaration format for the ② property: modifier data type variable name = initialization value;//java is a language of strong data types
③ Operations on property Assignment: 1. Default initialization 2. Explicit initialization 3. Initialization of code blocks 4. Initialization of constructors; 5. Calling methods, properties for assignment
2.2 Method ① Format: modifier (other keyword: static/final/abstract) return value type method name (formal parameter list) {//Method body}
Override of the ② method (overload) vs method (override overwrite)
The parameter passing mechanism of the ③ method: value passing (difficulty)
2.3 Constructor ① The role of the constructor: 1. Create an object of the Class 2. Initialize the member variables of an object
The ② constructor can also be overloaded.
2.4 Code block main role: Used to initialize the class's member variables
Category: Static blocks of code vs non-static blocks of code
2.5 Inner Class ① classification: Member inner class (member of static vs non-static member) vs Local Inner class (class declared within method)
②: ① How to create an object of a member's inner class (for example, to create an object of the bird class and the dog Class)
② How to distinguish variables that call external classes, inner classes (especially when the names of variables are identical)
③ use of local inner classes (see Testinnerclass1.java)
3. Initialization of classes (objects that create classes)
3.1 How to create an object of a class. such as: person p = new person (); Date d = new Date ();
3.2 Memory Resolution:
① stack: Local variables, reference names of objects, reference names of arrays
Heap: New "Things"
Method Area: (string constant pool)
Static domain: Storing static variables in a class
② How to understand the process of creating an object that is loaded in memory (understanding)
3.3 Subclass Object Instantiation of the whole process: Subclass SC = new subclass ();
4. Three main features of object-oriented:
4.1 Package Nature:
① invokes and modifies the public getter and setter methods by privatizing member variables of the class
② can also "encapsulate" other structures of a class
③ permission modifier: public protected default Private
4.2 Inheritance:
By inheriting a class A to another Class B, you can get the structure in Class B (primary: property, method, constructor). Subclass: Class A parent class: Class B
Inheritance of classes in >java: Single-Inheritance.
4.3 Polymorphism:
① embodiment: Overloading and rewriting of methods; The polymorphism of a subclass object person p = new Student ();
② use of sub-class object polymorphism: Virtual method invocation.
③ upward transformation downward transformation Student s = (Student) p; Recommended before a downward transition: if (P instanceof Student) Avoid classcastexception exceptions
5. Other keywords:
5.1 This: Modifies the property, method, constructor. Represents: The current object or the object currently being created
5.2 Super: Modifies properties, methods, constructors. The corresponding structure of the parent class is called explicitly, especially if the child parent class has the same name as the method, property
5.3 Static: Modifies properties, methods, code blocks, inner classes. Loads as the class loads!
5.4 Final: Modifies classes, properties, methods. means "the final"
5.5 Abstract: Modifying classes, methods
5.6 Interface: Represents an interface, (an interface is a structure that is tied to a class). "Implements" between classes and interfaces.
When a class has multiple inheritance, the interface has the same method name, and the return value type is the same, the system will be treated as a method, if the return value is not the same, the compilation error cannot pass
The properties defined in the interface are default to public static final.
The methods defined in a few mouths are default to public, and methods in the interface are not implemented.
5.7 Package Import ...
>abstract cannot modify attributes, constructors, and cannot be shared with final static private.
Java Object-Oriented (string)