The four basic features of inheriting encapsulated polymorphic abstraction in JAVA Oo and being named Object-oriented programming
Encapsulation hides the internal implementation mechanism of the class so that it can change the internal structure of the class without affecting the user's premise , while protecting the data
Inheritance is to reuse the parent class code
Polymorphism refers to the ability of an object to have multiple forms. Subclasses of a class can define their unique behavior while sharing some of the same characteristics of the parent class.
In particular, polymorphism can be understood as:
1. The first is that different methods of the object can use the same method name, which is the concept of overloading. (overloading refers to the same method name in a class that has the same parameter list)
2. The same object performs the corresponding behavior according to different messages, or it can be thought that sending a message to an object allows the object to choose the appropriate behavior
So polymorphism can be divided into static polymorphic and dynamic polymorphic
In layman's terms: static polymorphism means that you can decide which method to call when the system calls the method and the dynamic method needs to be judged when the user instantiates it.
Here's how the polymorphic implementation works:
Use dynamic binding and override mechanisms in Java to implement polymorphic
The default dynamic binding in Java so-called dynamic binding means that for a method defined in a parent class, if the method is overridden in a subclass, a reference to the parent class type is called to the subclass's method, which is dynamic binding
In general, methods implemented and defined in subclasses cannot be called in a parent class, and methods that are only defined in the parent class and implemented are called in the subclass.
For a multi-state summary:
1. Using a reference to the parent class type to point to the object of the child class
2. The reference can only call methods defined in the parent class and cannot invoke methods unique to the subclass
3. If a method in the parent class is overridden in a subclass, the method in the subclass is called when the method is called
4. In polymorphism, subclasses can call all methods in the parent class
The multi-state interface of JAVA oo key content