Java object-oriented
OOP --> Object Oriented Prigramming: 1. abstract: describes things in the real world as the process of classes, objects, and methods in the system. In this process, data and information that you do not want to care about are displayed, the reserved data is used to implement system-specific functions. 2. Encapsulation: hides the details of object implementation (you do not need to know these details) and only provides some common methods to present the object functions. 3. inheritance: it is an important method for implementing software reuse based on object-oriented methods. With Inheritance, people can build a new class based on existing classes. Subclass inherits existing classes, it is to reuse the methods and attributes of the parent class. In addition, some new methods and attributes can be added to the Child class to meet new requirements. 4. polymorphism, there are two types of variables referenced by Java, which are determined by the value-assigned object type during compilation. If the type and value-assigned value are different during compilation, the so-called polymorphism occurs. an object can have multiple references at different times, but a single reference can only have one object at a time. If a reference modifies an object, other references will be affected. the declared object is not a real object, but a reference. It is stored in the stack space for the program to quickly read and call, then, a continuous area is opened up in the stack space to store real data content. in Java, objects are stored in the same way. The first is to store the reference (name) in the stack space. Then, the real object is created using the new keyword and stored in the heap space. in the same category, each constructed object has a set of attributes, which are not affected by each other. but it is true that the methods in the public class are stored in a place called the method area. an object is a real individual and the real execution body of a function. A class is a template of an object. It can be regarded as a standard or collectively referred. parameter: formal parameter: The parameter used for method definition is a formal parameter ). actual parameter: The value passed when calling a method is called the actual parameter (real parameter ). the parameter is essentially a value transfer. restricted scope modifier: public can use the default with the lowest security level throughout the project (meaning nothing is written) by default, you can use protected to protect the class and the local weight. You can use private to only use the final keyword with the highest security level in this class: class, attribute, and method can be modified. the final modified class is the final class and cannot be inherited. attributes modified by final cannot be changed. the final modification method cannot be overwritten by the subclass ). how to Use: Object Name. method Name (); eg: Person person = new Person (); person. say (); methods can be called to each other, but cannot be defined by nesting. how to define attributes: modifier attribute type attribute name; how to use attributes: Object Name. attribute name; eg: Person person = new Person (); person. age = 18; constructor features: the constructor name must be the same as the class name (uppercase ). the constructor cannot return any values, including void. if no constructor is written in the class, the compiler will construct an empty parameter by default. If any constructor is written, the null parameter constructor provided by default will be overwritten. if multiple constructor methods are written in a class, they are considered as overload of the constructor. You can use this (parameter) to call the methods in this class. the constructor cannot be displayed and can only be called implicitly using the new keyword. the constructor is to create an object. in enterprise development, we generally need to write the empty parameter constructor. Even if the program cannot use the constructor, the empty parameter constructor cannot be specified in our program. call the constructor in this class through this (parameter. this (parameter); must be written in the first line of the constructor, that is, this (); without any executable code. new Keyword: opens up memory space for the object to be created. create an object by calling the constructor of the class. assign the object address to the declared referenced object. when an object is built using the new keyword, parameters are written in parentheses. If there is no parameter, leave it blank. If there is a parameter, the actual parameters passed in must be consistent with the formal parameters (type, quantity, and order) during definition ). method Overload: in the same class, the method name is the same, and the parameters are different (the number of parameters is different, and the parameter type is different), which is called method Overload. override: The identifier of method rewriting is @ Override. the name of the overwritten parent class is the same as that of the method. if a parameter exists, the parameters of the parent class and subclass must be identical (number, type, and order ). the returned values of the parent class and subclass must be identical. the qualified modifier of the subclass can be the same as or greater than the parent class, and the permission cannot be less than the parent class. private methods cannot be inherited or overwritten. the ultimate purpose of method rewriting is to change the implementation of the parent class method in the subclass.