Encapsulation: Hides the properties and implementation details of an object, exposes only interfaces externally, and controls the level of access to read and modify properties in the program. The abstract data and behavior (or function) are combined to form an organic whole, that is, the data and the operation of the source code of the data are organically combined to form a "class", where the data and functions are members of the class. The purpose of encapsulation is to enhance security and simplify programming, so that the user does not have to understand the specifics of the implementation, but simply uses the members of the class through the external interface, a specific access permission. The basic requirement for encapsulation is to privatize all properties, provide getter and setter methods for each property, and, if there is a constructor with a parameter, write a constructor without parameters. The classes that have been written are often tested at development time, so there are times when you have to rewrite the ToString method, but this is not necessary.
Inheritance: Implements code reuse through inheritance. All classes in Java are obtained by inheriting the Java.lang.Object class directly or indirectly. Inherited classes are called subclasses, and inherited classes are called parent classes. Subclasses cannot inherit member variables and methods in the parent class that have access rights private. Subclasses can override the parent class's methods and name member variables with the same name as the parent class. However, Java does not support multiple inheritance, which is the ability of a class to derive from multiple classes of superclass. Minimizing inheritance in development is done to reduce the coupling of the program.
Polymorphism: Polymorphism is also divided into design-time polymorphism and run-time polymorphism, such as overloading is also known as design-time polymorphism, and for overridden or inherited methods, the Java runtime system determines which method is called run-time polymorphism based on the type of instance that invokes the method. In summary, the typical feature of object-oriented design is inheritance, encapsulation and polymorphism, which are the key to the popularity of object-oriented.
Packaging
The default value for the properties of a class in Java is not private, and to hide the property's method, you can add the private modifier to restrict access to the inside of the class only.
For a private property in a class, the private property is guaranteed to operate and secure for the private property by giving it an opposite method (Getxxx,setxxx ()).
The encapsulation of the method, the exposed disclosure, the hidden hidden.
Inheritance of Java
Inheritance is a kind of multi-class thing with common characteristics, which is then abstracted into a class.
Inheritance in Java uses the extends keyword, and the Java middle Word allows single inheritance, which means that a class can have only one parent class.
The construction method cannot be inherited .
Overrides in the Java method
Methods that inherit from the parent class are overwritten when there is a method in the subclass that has the same name and is accessible from the parent class that returns the same argument list.
Super () keyword
Super (), which indicates that super () can only be the first sentence in the constructor method when the constructor method of the subclass calls the parent class.
Polymorphism in Java
There are two polymorphic mechanisms: compile-time polymorphism, run-time polymorphism
1. Overloading of methods: overloading refers to multiple methods with the same name in the same class, but these methods have different parameters. , so at compile time you can determine exactly which method to call, which is a compile-time polymorphism.
2. Method overrides: Subclasses can override the methods of the parent class, so the same method will behave differently in the parent class than in the child class. In the Java language, a reference variable of a base class can point not only to an instance object of a base class, but also to an instance object of a subclass, as well as to an instance object of its implementation class.
Java three major features encapsulation, inheritance, polymorphism