Java is an object-oriented programming language, andtheJava language provides the basic functions of defining classes, defining properties, and methods. A class can be considered a custom data type, you can use a class to define a variable, a variable that defines a reference type, it refers to an object of a class, an object is created by a class, a class is used to describe the common characteristics of something in the objective world, and the concrete existence of a class object, theJava The class's constructor is used in the language to create an object of the class.
Java supports three main object-oriented features: encapsulation, inheritance, polymorphism,java provides private,protected, and public Three access control modifiers for a good encapsulation , providing the extends keyword to implement inheritance. Subclasses inherit the parent class to inherit the properties and methods of the parent class, and if access control allows, the subclass instance can invoke the method defined in the parent class directly. Inheritance is an important means of reusing a class, and in addition, it can be implemented by combining relationships, and in a way, combination and inheritance have the same function. Using inheritance to implement the reuse of a class, the subclass object can be directly assigned to the parent class variable, which is polymorphic, the programming is more flexible, and the use of composite to implement the reuse of the class, there is no such flexibility.
Constructors are used to initialize an instance of a class, and the constructor supports overloading. If more than one constructor contains the same initialization code, the code can be placed in a normal initialization block, and the initialization block is always called before the constructor executes. In addition to this,Java also provides static initialization blocks for initializing classes that are executed during the initialization phase of the class. If a class in the inheritance tree needs to be initialized, all classes in the inheritance tree will be initialized.
And look back on Java for a week.