encapsulation

Encapsulation privatized the properties of an object while providing methods for properties that can be accessed by the outside world. If the properties do not want to be accessed by the outside world, we do not need to provide methods to access them. But if a class has no methods to access from the outside world, then that class is meaningless.

inheritance

Inheritance is the technique of using the definition of an existing class as a 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 can not selectively inherit the parent class. Using inheritance makes it very easy to reuse old code.

Here are three things to remember about inheritance:

  1. A subclass owns all the attributes and methods of the parent object (including private attributes and methods), but the private attributes and methods of the parent object are not accessible to the subclass.

  2. Subclasses can have their own attributes and methods, that is, they can extend their parent class.

  3. Subclasses can implement the methods of their parent class in their own way. (More on that later).

polymorphism

So-called polymorphism is refers to the 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, It must be decided during the running of the program.

Polymorphism can be implemented in Java in two forms: inheritance (overwriting the same method by multiple subclasses) and interfaces (implementing the interface and overwriting the same method in the interface).