Java Basics -- Basic Concepts

Java Basic Notes

 

1. Abstract encapsulation, inheritance, polymorphism

2. Expression of polymorphism

  -- Overloading, Overriding, Inheriting, Implementing

  -- is a generic mechanism                                                        

3. Inheritance and multiple inheritance of inner class functions

     -- External: that is, a class object can be incarnated as multiple other types of objects to be used by methods passed to other class objects (polymorphic representation)

     -- Internal: Multiple inner class objects are used as member properties or local variables in outer class objects (inheriting their own functions)

4. A java class can only inherit one concrete or abstract class , and each inner class can also only inherit one concrete or abstract class, but a class can have multiple inner classes, that is, it realizes the function of multiple inheritance-- 

   -- The inner class object can be obtained through the method of the outer class, for example: otherClass.method(outter.getInnerA()); otherClass.method(outter.getInnerB());

 

5. Abstraction

   Class - an abstraction of something concrete

  Interface - abstraction of classes, that is, to extract common features of multiple classes

  For example: Audi A4 is a concrete object, Audi is a class -- is an abstraction of multiple models of cars. Car is the parent class of Audi. Car is an interface -- an abstraction of Audi and BMW.

6. Use polymorphism (inheritance, interface) to replace the use of instanceOf. When designing a class interface, you can add carType members and get and set methods, so that when using parent class or interface references, you can use this method to get the corresponding instance of the specific instance. Types of

    Audi A4 (instance)-->Audi car (subclass)-->Car (parent class)-->Car interface

    BMW X5 (instance)-->BMW car (subclass)-->Car (parent class)-->Car interface

  --In the actual business scenario, there may be multiple inheritance relationships between the subclass and the parent class

  --Car interface definition getCarTye() method definition, which is implemented in the car parent class. When instantiating the object, the car parent class will be instantiated first, so the Audi car subclass does not need to implement the method in the car interface, because the parent class object already has (Inheritance means that child objects can use the properties and methods of parent and grandparent objects)

  --When an object is instantiated, the constructor of the base class will be called first and then called down level by level

  --Call the car parent class setCartype method when instantiating the A4 object-- A4

  --Call the car parent class setCartype method when instantiating the X3 object-- X3

  --The interface reference calls getCarType to take out the corresponding type

 

7. Overload

  -- only care about the class name and method parameter list

8. Initialization and Constructors

  -- 1. When instantiating an object, first call the constructor of the base class of the current class, recursively call upwards until the root is reached

  -- 2. Initialize member properties down the hierarchy

  -- 3. Call the constructor down the hierarchy

9. There is no initialization operation for local variables, because the unassigned local variables are basically errors ignored by the programmer, so the compilation prompts an error

10. Garbage collection only reclaims the memory occupied by java new objects, and the memory occupied by calling local methods needs to be cleaned up by calling the finalize() method

11. Abstract classes

  -- Abstract classes cannot be instantiated. Extract and implement the same business logic into methods (abstract classes can have implementation methods), declare abstract methods for other business logic that needs to be customized, and implement them by concretely inherited classes.

  --The sub-implementation class needs to do: 1. Implement the abstract method to realize personalized business logic, 2. Call the common method of the parent abstract class to complete the entire business logic

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326852672&siteId=291194637