Three Object-Oriented Features of Java

package
definition:
Encapsulation is an important principle of object-oriented methods, which is to combine the properties and operations (or services) of an object into an independent whole, and to hide the internal implementation details of the object as much as possible.
inherit
definition:
Inheritance is one of the most prominent features of object orientation. Inheritance is a new class derived from an existing class. The new class can absorb the data attributes and behaviors of the existing class, and can extend new capabilities.  Java inheritance is a technology that uses the definition of an existing class as the basis to create a new class. The definition of a new class can add new data or new functions, or use the functions of the parent class, but cannot selectively inherit the parent class.  
Classification:
Inheritance is divided into single inheritance and multiple inheritance. Single inheritance means that a subclass can only have at most one superclass. Multiple inheritance means that a subclass can have more than two superclasses. Since multiple inheritance will bring ambiguity , single inheritance should be used as much as possible in practical applications. Classes in the Java language only support single inheritance, while interfaces support multiple inheritance. The function of multiple inheritance in Java is achieved indirectly through the interface ( interface ) [1]  .  
polymorphism
definition:
Polymorphism is the ability to have multiple different manifestations or forms of the same behavior.
use:
When using polymorphism to call a method, first check whether the method exists in the parent class, if not, it will compile an error; if so, call the method of the same name in the subclass.
advantage:
Can make the program have a good extension, and can be common to all classes of objects.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324651725&siteId=291194637