Java BASICS (7) JavaSE and javase
Object-orientedProcess-oriented: process-oriented thinking emphasizes process (action ).
Object-oriented: Objects (entities) are emphasized in object-oriented thinking ).
Features:1. Object-oriented is a common idea. Meets people's thinking habits.
2. The emergence of object-oriented architecture simplifies complicated problems.
3. The emergence of Object-oriented has changed the performer in the process to the conductor in the object.
Class and object:The java language describes things in real life and is embodied in the form of classes.
The description of a thing usually focuses on two aspects: one is attribute and the other is behavior.
You only need to clarify the attributes and behaviors of the transaction and define it in the class.
Class: The description of a transaction.
Object: an instance of this type of transaction. Created in java through new.
A definition class is actually a member of a definition class.
Member: member variable <--> attribute, member function <--> action.
Differences between member variables and local variables:1. member variables are defined in the class and can be accessed throughout the class.
Local variables are defined in functions, statements, and local code blocks and are only valid in the region.
2. member variables exist in heap memory objects.
Local variables exist in the stack memory method.
3. member variables exist with the creation of objects and disappear with the disappearance of objects.
Local variables exist with the execution of the region and are released with the completion of the region.
4. All member variables have default initialization values.
No Default initialization value for local variables.
Anonymous objectAnonymous object: an object without a name, such as new Car (); is a simplified format for defining objects.
Note the following when using an anonymous object:
1. When an object calls a method only once, it can be simplified to an anonymous object.
2. Anonymous objects can be passed as actual parameters. For example, show (new Car ());
EncapsulationEncapsulation: hides the attributes and implementation details of an object and only provides public access.
Benefits:Isolate changes.
Easy to use.
Improve reusability.
Improve security.
Encapsulation principles:Hide all content that does not need to be provided externally.
Hide all attributes and provide public methods to access them.
Private: private. It is a permission modifier used for member variables and cannot be used for local variables.
Private content is only valid in this class.
Note: Private is only an embodiment of encapsulation.