1. Inheritance:
1) Purpose: Avoid code duplication and facilitate code reuse
2) implement inheritance through extends
3) Parent class/base class: Properties and behaviors common to all subclasses
Subclass/Derived class: properties and behaviors specific to subclasses
4) When a subclass inherits from a parent class, the subclass has a method:
Subclass Method + Parent class method
5) A parent class can have multiple subclasses
A subclass can have only one parent class----single inheritance
6) Inheritance has transitivity
7) Java stipulation: The parent class must be constructed before the subclass is constructed
If the construction of the parent class is not called in the subclass construct, then the default super () is the non-parametric construct of the parent class, and if it is tuned, it is no longer provided by default.
Super () calls the parent class construct, which must be in the first sentence of the subclass construct
2.super: Refers to the parent class object of the current object
Usage:
Super. Member variable name-------Access member variables of the parent class
Super. Method Name ()---------method for calling the parent class
Super ()----------------Call the construction method of the parent class
3. Upward Styling:
1) The reference of the parent type to the object of the child class
2) What you can point out, see the type of reference
4. Override of the method (override):
1) occurs in a parent-child class with the same method name, with the same argument list and different method body
2) When the override method is called, look at the type of the object
2. Overrides and overloads differ:----Common face questions
1) Rewrite: parent-child class, method name is the same, parameter list is same, method body is different
Follow the run-time bindings to invoke methods based on the type of the object
2) Overloading: In a class, the method name is the same, the parameter list is different, the method body is different
Follow the "compile-time" bindings, based on the type-binding method of the reference
3.package:
1) Function: Avoid naming conflicts of classes
2) package name can have a hierarchical structure
3) Recommendation: Package name all letters are lowercase
4) The fully qualified name of the class: package name. class Name
Import
1) Function: Declare class/Introduce class
2) classes in the same package can be accessed directly
Classes in different packages want to access:
2.1) First import declaration class again Access class (recommended)
2.2) The full name of the class-----too cumbersome (not recommended)
5. Access Control Modifiers:
1) Public: Open, any class
2) Private: proprietary, this class
3) Protected: Protected, this class, sub-class, same package class
4) Default: Do not write anything, this class, the same package class
Access adornments for classes: public and default
Access adornments for class Members: 4 kinds are available
6.static: Static
1) Static variables:
1.1) Modified by static
1.2) belongs to the class, there is a method in the area, only one copy
1.3) often accessed through the class name.
1.4) When to use: all objects have the same data when used
2) static method:
2.1) Modified by static
2.2) belongs to the class, there is a method in the area, only one copy
2.3) often accessed through the class name.
2.4) No implicit this pass
Instance members cannot be accessed directly in a static method
2.5) When to use: the operation of the method is only relevant to the parameter and is not related to the object.
3) static BLOCK:
3.1) Modified by static
3.2) class, class is automatically executed during load
Class is loaded only once, so static blocks are only executed once
3.3) When to use: often used to load/initialize static resources (Pictures, audio, video ...)
7.final: cannot be changed
1) modifier variable: variable cannot be changed
2) Modification Method: Method cannot be overridden
3) Modifier class: class cannot be inherited
Java Basics Summary Two-inheritance, rewriting, overloading-related knowledge points