One, foreword
This article is taking part in the “Java theme month – Java brush the question punch card”, for Java related brush the question knowledge this column is the first time to do, I will share the relevant knowledge point from the simple to the complex, if there is something wrong, also ask big man to correct.
This article continues to share the basics of Java learning, the three features of Java object-oriented programming: encapsulated inheritance polymorphism, as shown below.
Two, knowledge points
1, encapsulation
Encapsulation privatizes the properties of an object and provides methods that can be accessed by the outside world. If the properties do not want to be accessed by the outside world, there is no need to provide methods for the outside world to access, but if a class does not provide methods for the outside world to access, then the class is meaningless.
2, inheritance,
Inheritance is the technique of using the definition of an existing class as the foundation to create a new class. The definition of the new class can add new data or new functions, or use the functions of the parent class, but it cannot selectively inherit from the parent class. Using inheritance makes it very easy for developers to reuse previous code.
3, polymorphism
Polymorphism refers to procedures defined in the reference variable is pointing to the specific type and referenced by the variable from method calls are not sure when programming, but during the program is run to determine, that is, a reference variable will point to which class instance of the object, the reference variable from method calls the method to realize exactly is which class, must can decide during the program is running.
3. Matters needing attention
1. There are three points about inheritance that need to be strengthened:
① A subclass has all properties and methods (including private properties and private methods) of a superclass object; But the private properties and methods in the superclass are not accessible to the subclass, they just own them. ② Subclasses can have their own properties and methods, that is, subclasses can be extended to the parent class. (3) Subclasses can implement methods of the parent class in their own way.
2. Two forms of polymorphism
Polymorphism can be implemented in Java in two forms: inheritance (overwriting of the same method by multiple subclasses) and interface (implementing the interface and overriding the same method in the interface).
Four,
When learning Java, the necessary skills are the characteristics of object-oriented programming, but also please learners must consolidate the relevant knowledge points when learning. By the end of this article, the reader should have a clear understanding of the features of object-oriented programming. Above is the knowledge point of this article, welcome to criticize.