Object-oriented: Object -oriented thinking emphasizes objects (objects with functions), and the process of focusing on action encapsulates the function into objects, we don't need to do anything we want to do, we just need to find the object with that function.
Three main features of object-oriented: encapsulation, inheritance, polymorphism
Encapsulation: is the preservation of a function, we put a method or function into the class, we need to find the object that encapsulates this function, and then call this object directly, the common functions or methods to encapsulate, can improve the reusability of code.
Benefits of Encapsulation:
1. Improved code reusability, we can encapsulate common methods into objects, when we need to use this function, only need to find the object with the function
2. Improve the security and standardization of the Code, specify the property of the object to private (privatized), and then to the property to configure the set () and Get Method () specification property acquisition and assignment
inheritance: with keyword: extends (subclass name extends parent class name)
An inherited class becomes a subclass or a derived class, and the inherited class becomes either a parent class or a base class or a superclass.
When you have the same properties or methods in multiple classes, we can extract these common properties and methods into a single class, and then inherit the individual class, saving the code and making the program easier to expand.
object is the parent class for all other Java classes
Inheritance: Subclasses can directly use properties and methods that are not private to the parent class after inheriting the parent class
Java can only be single-inheritance, one can have only one parent class, support multi-layer inheritance such as: b Inherit a C and then inherit B
When inheriting, understand the relationship between class and class, and make clear B is a
Polymorphism : a variety of forms that exist in a certain class of things
Characteristics of polymorphism:
Can hide object-specific features, only publicly shared members
The prerequisite for a polymorphic implementation is that two classes must have a relationship
Polymorphism improves code extensibility
A small rookie, a shallow understanding of Java, if there is a problem, but also hope to point out, thank you!
Java Object-Oriented understanding