, Feng small Java object-oriented programming thought
Object-oriented three features: encapsulation, inheritance, polymorphism
Packaging:
Syntax: Property privatization (private), providing a way to provide relative get/set to access (public),
The judgment of the business logic corresponding to the data of the attribute in the method of Set/get
Idea: Packages outside of the program cannot directly access the properties of this class, and need to pass through the methods provided by this class
access the properties of this class to improve the security of your code.
Other knowledge points related to:
construction Method: Used to describe the object creation process, you can create objects quickly by constructing the method.
This keyword: represents this class of objects, calling the properties, methods, and construction methods of this class.
Method Overloading: Method name is the same, parameter list is not the same
inheritance:
Syntax: Subclass extends Parent
idea: Multiple classes describe common features or behaviors that can be extracted from the common parts of these
classes to create their parent classes.
Inheritance Benefits: Subclasses share the code of the parent class, improving the reusability of the Code; Code
later extension and maintenance, just add the corresponding subclass.
Other knowledge points involved:
Super Keyword: An object representing the parent class, calling the parent class's properties, methods, and construction methods.
abstract Keyword: abstract, decorated class, cosmetic method.
static keyword: static, cosmetic property, method, code block, inner class
final keyword: Finally, decorated properties, methods, classes
method Overrides: The method name is the same, the parameter list is the same, the return value type is the same,
modifier greater than or equal to the access modifier of the parent class
Polymorphic:
Syntax: Parent class object name =new subclass ();
Thought: A reference to a parent type can point to the memory space of a child class object in memory,
It is convenient to design the parameters and return value types of the method, you can
Designed to be a parent object, such a method is relatively concise when implemented, and in late
The method is easier to extend.
In code, polymorphic use is more of a parent class reference to a subclass object,
Automatically type conversions (up), but sometimes you need to call subclasses
In their own things, this time you need to also atomic class, called coercion type conversion
(downward transition), use the instanceof operator to do the type of
Judge.
The idea of Java object-oriented programming