Object-oriented Basic concepts
1, object-oriented (OOP, OOD) three major features: encapsulation, inheritance, polymorphism. Note that abstraction is not one of the characteristics
2, object-oriented programming is to abstract the data, and functional programming is to abstract the behavior. In the real world, data and behavior coexist, and so do programs, so we have to learn both of these programming ways.
3, the concept of the class is an abstract concept, including data and operations on the data, where the data is a property or member variables, the operation of the data is the method.
4. The concept of an object is a more specific representation of a class.
5, the function is free of the method outside the class, Java is not supported, compile errors.
Packaging
1, encapsulation: the data and the operation of the data are packaged together.
2, Java method parameter pass only the value, for the original data type pass the value of the variable passed in the past; For reference data type is passed the address of this reference type variable, pass the address value, this value is constant cannot modify, so, C + + can pass pointer, that is can change the address value.
3. You need to perform three steps to instantiate (new) an object:
1) Open up a memory space;
2) Call the constructor method of the class;
3) Returns the generated address of the object to the reference type variable.
4, the specific process of instantiation:
1) The static domain initialization of the parent class, the initialization of the static member variables of the parent class and the execution of the static code blocks should be in the order of the member variables and code blocks;
2) Static domain initialization of subclasses, initialization of subclass static member variables and execution of static code blocks should be in order of member variables and code blocks;
3) Initialization of non-static domain of parent class, initialization of non-static member variable of parent class;
4) The parent class constructor method is called;
5) Initialization of non-static domain of subclass, initialization of non-static member variable of subclass;
6) The subclass constructor method is called.
Inherited
1. Inheritance: Java single inheritance, subclass inherits parent class.
2, about the characteristics of inheritance:
1) The construction method cannot be inherited;
2) Subclass in the constructor method by default called the parent class of the non-parametric construction method, in other words if the parent class does not have such a construction method, then the runtime will error;
3) You can call the constructor of the parent class by Super (), but this statement must be the first sentence of the constructor, and the same as this ().
3, Method overrides (override) and overloads (Overload), overrides are subclasses that override the parent class method, and overloads are the same method names with different parameters.
Polymorphic
1, polymorphism: Late binding, that is, at compile time is not polymorphic, but in the runtime only polymorphic, so that rewrite is run-time polymorphism, and overloading is non-runtime polymorphism.
2, for the same name method call sub-class precedence, but the same name property call is the parent class first;
3, about the multi-state considerations:
1) The static methods and properties can be overridden by the quilt class, but also the quilt class can be rewritten, he and ordinary non-static methods in the inheritance is different; here is a hidden problem, such as a static method and a static property of the superclass, this time a subclass inherited him, Then all these static methods will inherit, and at this time the subclass also overrides this property and method, note that the rewrite can not change the static, otherwise it will compile error;
If, using subclasses to call this method and property directly, the return is the subclass definition, in fact, the parent class is hidden;
If, using an instance of a subclass, and this instance is a subclass type, the return is defined by the subclass, and the parent class is hidden;
If you take an instance of a subclass, but this instance is the parent class type, it returns the parent class definition, that is, the subclass is hidden;
The conclusion is: by the type itself to determine polymorphism;
2) for non-static properties, as is the case above, his polymorphism is entirely determined by the type, not the object itself;
3) for non-static methods, and the above is not the same, his polymorphism is determined by the object itself, so it is run-time to know.
4, about final use precautions:
1) A final modified class cannot be inherited, such as a string
2) The final modification method cannot be overridden, but can inherit, the default is also static, but can not be rewritten;
3) The final modified property cannot be assigned two times, but can be inherited, and can be overridden with the same name, in fact, is the same as static, the default is static
Java Review--oop