Functions of 1.abstract can only be in the abstract class
2. Overloading of functions
Multiple function names are the same in a class
Differentiate them by parameter list (parameter type, order, number)
Println is the function overload, depending on the parameters, choose a different function
3. Constructors
The function name is the same as the class name, there is no return type, public
The system is called automatically, and when an object is instantiated, the constructor is called
Can not be called by other means, the main completion of initialization work
Add: There must be a constructor in the class, and if the user does not display a definition constructor, the Java default assigns the parameterless constructor, and the parameterless constructor is no longer assigned once the user display has defined the constructor.
4. Static initializer
Static { // statement }
Features: class initialization, the owning class is added to memory, no return value, no parameters, and the variables must be static.
Public classaccount{Static intAccountno = 0; PublicAccount () {Accountno++; System.out.println ("BB"); } Static{ //Static initialization Valuesaccountno=1000; System.out.println ("AA"); }} Public classexample{ Public Static voidMain (string[] args) {Account a=NewAccount (); System.out.println (A.ACCOUNTNO); Account B=NewAccount (); System.out.println (B.ACCOUNTNO); }} results: Aabb1001BB1002
Conclusion: Static statically class initializers are executed earlier than other functions, executed only once, and after static int accountno=0;
Add: Static initialization is performed when the class is instantiated.
5. Terminator
protected void Finalize () { // statement }
Execution conditions: When the garbage reaches a certain number, and the system is not very busy, the garbage collection thread is automatically completed and the memory of all the garbage objects is freed up.
6. Object-Oriented Programming
Encapsulation (hidden details, permission control), inheritance (Hierarchy of classes), polymorphism (method name is the same, implementation differs)
7. Object's memory model
Stacks: Storing basic data types and objects
Heap: Storing object instances
Bird a = new Bird ();
The final decorated class cannot be inherited
Final modifier member variable, indicating that it cannot be changed and can be understood as a constant
Class inheritance: Subclasses cannot inherit private methods of parent class
Coverage of Members:
1) Overwrite of variable
- The member variable of the child class has the same name as the member variable of the parent class
- The override of a variable is independent of the type and is related only to the variable name
- When a subclass executes a method that inherits the parent class, the member variables of the parent class are processed
2) Coverage of functions
- The member method of the subclass is the same as the prototype of the member method of the parent class
- The override of a function is not only related to the method name, but also to its parameter type, order, number, return value
Inheritance of constructors
- Subclass unconditional Inheritance Parent class without parameter constructor
- The subclass executes the parameterless constructor of the parent class before executing its own constructor
- Subclasses can invoke the constructor of a parent class by using the Super keyword in its own constructor, which must be the first executable statement in the subclass constructor.
Public classSwanextendsbird{ PublicSwan () {System.out.println ("Swan!"); } PublicSwan (intnum) {System.out.prinln ("Lake!"); }} Public classbird{ PublicBird () {System.out.println ("Bird!"); }} Public classexample{ Public Static voidMain (string[] args) {Swan a=NewSwan (); Swan b=NewSwan (1); }} results: Bird!Swan!Bird!Lake!
Public classSwanextendsbird{ PublicSwan () {Super(); System.out.println ("Swan!"); } PublicSwan (intnum) { Super(); SYSTEM.OUT.PRINLN ("Lake!"); }} Public classbird{ PublicBird () {System.out.println ("Bird!"); } PublicBird (intCDoubles) {System.out.println ("Cs!"); }} Public classexample{ Public Static voidMain (string[] args) {Swan a=NewSwan (); Swan b=NewSwan (1); }} results: CS!Swan!CS!Lake!conclusion: After using Super, the parent-class lunch constructor is no longer called by default.
NULL indicates null object
This represents a reference to the current object (which can be understood as an alias), a method that can invoke the current object, a constructor for the current object, and a reference to the current object as an argument to another method.
Super represents a reference to the parent class object of the current object, a method that can invoke the parent class object of the current object, a constructor for the parent class object of the current object, and a reference to the parent class object of the current object as an argument to another method.
Polymorphism
- Overload
- Covered
- Parent class reference to child class object instance: Early binding (refers to compile-time binding); Late binding (runtime binding)
Basic Java Knowledge