Java has three major features, encapsulation, inheritance, polymorphism, but the average person is not able to understand these three characteristics I'm going to share my experience here.
1. Encapsulation: The public public, the private private
The properties of the class are private, the properties of the class are generally private, and the method of the class: the public public, the private private;
class, encapsulates data and methods, encapsulates the implementation process, interfaces are parameters and return values; Data prototype class: Also called entity class
1) Get/set method; a get is only provided for a property that does not provide a set method, which is read-only and cannot be modified outside the class;
2) provide unified parameter checking, give and check on set, judge legality and security; The properties are private and provide Set/get method, which is a general component called JavaBean;
2, Inheritance: Any parent class where applicable, subclasses must be applicable
Simple code reuse does not need to inherit extends: inheritance, is actually the extension of the parent class;
What is the process of generating an object?
1) Allocating object space;
2) Assign the initial value to the attribute; boolean:false; value type: 0 or 0.0; Object type: null;
3) Call the constructor method;
3. Polymorphic: Overloads of multiple methods in a class are called polymorphic, and the overrides of methods in parent-child classes are also called polymorphic.
There are two types of polymorphism: one is the reload of the method, the other is the method's cover
Polymorphic polymorphic and Object polymorphism (multiple forms of an object). Polymorphic must look at the subclass object as a parent object,
All polymorphism can be attributed to two theorems:
1). You can look at the object as a parent class object, once this is done, you can only call the parent class in the original defined properties and methods, that is, the extension of the subclass of the method or property can not be called.
2). When we look at a class object as a parent object, if the subclass overrides a method in the parent class, the child class is actually called after the overridden method.
JAVA three major features