Anything is object (all objects)
Abstract: extract useful information from a specific object.
An object has its inherent attributes. Its method is the behavior of an object (What can an object do)
Objects are simple (simple functions). Multiple objects can form a complex system (Objects call each other's methods)
The objects should perform their respective duties (simple functions) and do their best (to make their own functions the best ). (Weak coupling achieves the features of the objects described above)
Coupling of objects refers to the relationship between objects and systems. The coupling of objects should be as weak as possible, that is, the relationship between objects should be as weak as possible, and the relationship between objects and systems should be as weak as possible.
System insertion is the system stability after new objects are added to the system.
The alternative of an object is the system stability after the original object is replaced in the system.
Reusability: whether an object can be reused. The simpler the object function, the better the reusability. (Weak coupling of objects, strong reusability)
The process-oriented approach involves first having algorithms and then data structures (how to solve the problem)
Object orientation includes objects (data structures) and algorithms. (What to Do)
Class is the abstraction of some sets with the same attributes.
A class is a template of a class object, and an object is a concrete class.
Class is a new data type, class object.
Note: The scope of a local variable is within the defined code block. The local variable must be assigned a value before use. Two local variables cannot be named in conflict within the range of a coincidence. Local variables take precedence over local variables.
Variables include simple variables (original data type) and object variables.
Method definition:
1. modifier of the method (the order in which multiple modifiers appear is irrelevant) |
2. Return Value Type of the method |
3. method name | sequence
4. parameter table of the method | direction
5. exceptions allowed to be thrown in the method | Lower
Java cannot write any code after the return statement.JVM + interpreter = JRE, JRE + class library = JDK
In Java, the method overload has the same name and the parameter table is different. The return value type can be different. You must specify parameters and call a method. During compilation, the compiler selects an appropriate method based on the parameter. Therefore, overloading is also called polymorphism during compilation..
Nearby Matching Principle
If the data type in the parameter table of the method is different from the parameter type given during the call, it will be matched according to the proximity principle. (Type nearby and up conversion matching)
Note: You must specify parameters and call a method. Otherwise, an error occurs during compilation.
Object User (call methods of other objects) object (when a method in an object is called, make your own selection based on parameters)
Method 1, but different parameters may differ. The object is determined based on the parameter and transparent to the object caller.
Object creation process: 1. Allocate space 2. initialize attribute 3. Call the constructor (prerequisite: do not consider the inheritance relationship)
Constructor Syntax: no return value type. The constructor name must be the same as the class name. If no constructor is written in the class, the system provides a constructor without parameters.
Note:It is best to provide a construction method without parameters when writing a class..
How to obtain objects
The new class name () can be used to apply for space allocation in the heap space. An object in this form or. Example: Car c = new car ();
When a constructor with parameters is called, it is initialized when the new keyword or object is used, for example: Car c = new car ("yellow ")
The object variable stores the object reference (address encapsulation form)
This keyword
Indicates the current object (the object that calls the method and the object that is the current object), which can be used to distinguish between instance variables and local variables. This () indicates that other constructor methods in this class are used. Note that only the first line of the constructor can be written.
In Java, parameters are passed. Variables of simple types pass numerical values, and object variables pass a reference (address)