1. Inheritance
A. In the same. java file, only 1 public classes are allowed, and the public class has the same name as the filename.
b, if the public class does not exist in the. java file, it can be any legal name
C, in the member variable, the initial default value of the numeric base data type is: 0. The default value for the Boolean type is False
D, the default initial value of the reference data type is null.
E, if the constructor that creates the class is not displayed, the constructor generates a default parameterless constructor, and if the constructed method is defined, the constructor does not create a default constructor method that has no parameters.
2. Super keyword
A, in the parent class existing logic to add some of their own methods, you can use super. Need to be placed first in the current construction method.
B, when a subclass has a member variable of the same name as the parent class, or a member method of the same name, the element in the child class is greater than the precedence of the element in the parent class, so a method or member variable in the parent class needs to be called with the Super keyword
C, through super after directly with parameters, you can call the parent class construction method.
3, the construction method in succession
A, the construction of a subclass must call the construction method of its base class.
B, subclasses can use super (arguments ...) in their own construction methods. ) calls the construction method of the base class.
B.1, use this (arguments.) Another method of constructing this class is called.
B.2, if called Super, must be written in the first row of the subclass construction method.
C, if the constructor of the subclass is not shown in the construction method of the call base class, the system defaults to calling the base class's parameterless construction method.
D, if the subclass constructor method does not show a call to the base class construction method, and the base class does not have a parameterless construction method, then the compilation error.
4. Access Rights modifiers
A. Private permissions
Private can modify data members, construct methods, method members, and cannot decorate classes (this refers to external classes, regardless of inner classes). Members that are decorated by private can only be used in the class in which they are defined and cannot be called in other classes.
B, default permissions
Classes, data members, constructor methods, method members, all have the ability to use the default permissions, that is, no keywords are written. The default permissions are the same as package permissions, and the elements of the same package permission are called only in the class in which they are defined, and in the same package class.
C, protected permissions (protected)
Protected can modify data members, construct methods, method members, and cannot decorate classes (this refers to external classes, regardless of inner classes). Members that are modified by protected can be called in the class that defines them, in the same class as the package.
If classes with different packages want to invoke them, then the class must be a subclass of the class that defines them.
D, Public permissions
Public can decorate classes, data members, constructor methods, method members. Members that are modified by public can be called in any class, regardless of the same package or different packages, which is the most privileged modifier.
Ps:
E, not every modifier can be decorated class (refers to an external class), only public and default can.
F, all modifiers can be decorated with data members, method members, construction methods.
G, for the sake of code security, modifiers do not try to use the permissions of large, but applicable. For example, data members, if there is no special need, use private as much as possible.
h, modifiers are decorated with "accessed" permissions.
Public protected Default Private
√√√√ of the same class
Same package √√√
Sub-class √√
Different packages Yes
5. Method overwrite
A, you can override a method inherited from a base class as needed in a subclass.
b, the overriding method must have the same method name, parameter list, and return type as the overridden method.
C, the overriding method cannot use more restrictive access than the overridden method.
Strictly sequential private>default>protecte>public, this is related to polymorphism, speaking polymorphic will understand much.
When a place is decorated by a parent class, you can call a method of the parent class.
If the subclass accesses the method more rigorously, it may be inaccessible if the subclass is passed over.
6. The difference between overwrite and overloading
A, heavy load (overloading)
Overloading of methods in Java refers to the ability to create multiple methods in a class that have the same name but with different arguments (type and number of parameters) and different definitions.
The type of the return value can be the same or not different, but the overloaded function cannot be distinguished by just a different return value.
The method is called according to the parameter list to determine which method to invoke. Overloading is the representation of polymorphism in a class.
b, overwrite (overriding)
In Java, subclasses can inherit methods from the parent class by default, without having to rewrite the same method, but sometimes
Subclasses do not want to inherit the methods in the parent class intact, but instead make certain modifications, which are implemented by means of overwriting (also becoming overrides) of the method.
In Java, overwrite refers to the change in the subclass of the same name function implementation part of the parent class, but with the parent class's method names, return types, and parameters
The list remains consistent. That is, the subclasses redefine the functions in the parent class, and the new methods in the subclasses overwrite the original methods of the parent class. Overwrite is a polymorphic representation between a parent class and a subclass.
Inheritance in Java