1. Rules on inheritance: Subclasses cannot inherit private member variables and methods in a parent class
2. The overriding method must have the same method name, parameter list, and return value type as the overridden method, and cannot use a more restrictive access limit than the overridden method
3. Super: A reference to a parent class object in a Subclass object method
Use
1) referencing the members of the parent class object in the method of the Subclass object
Public String GetInfo () {
return Super.getinfo () + ", info" + info;
}
2) Call the constructor of the parent class in the constructor of the child class
-You can invoke the constructor of the parent class in a subclass by Super (argument list)
-By default, the constructor of the subclass invokes the parameterless constructor of the parent class
Public person () {
Super ();
}
-If the parent class defines a constructor with parameters, the system will no longer provide a parameterless constructor for the parent class, and a constructor for the parent class must be called in the constructor of the child class:
① the definition of a parent class to display an argument-free constructor
② calling the parameter constructor of the parent class explicitly in the constructor of the child class
-Similar to this, the super (parameter list) must be placed in the first row of the constructor, which indicates that this (argument list) and super (argument list) cannot appear at the same time
4. Polymorphism: variable of the same type, invoking the same method but producing a completely different behavior
-When the parent class's variable points to an object of a subclass, calling the method that has been overridden in the parent class
-In polymorphic situations (when the parent class's variable points to an object of a subclass), the newly added method of the subclass cannot be called
-In polymorphic situations, you can force type conversions on an object
1) Forced type conversions are only possible with parent-child relationships
2) The object of the parent class can be converted to the type of any subclass, but it may occur java.lang.ClassCastException
5. instanceof Operator:
-X instanceof A Tests if X is an object of class A, and the return value is Boolean.
-Requires that the class to which x belongs must be a relationship between the subclass and the parent class, or the compilation error
6. Forced type conversion for Java:
-Types from subclasses to parent classes can be automatically
-Parent class to child class must be cast
-The conversion of a reference type without an inheritance relationship is illegal
7. Equals and = =
1) = =
-Reference type comparison reference (whether to point to the same object)
-The data type must be compatible on both sides of the symbol, otherwise compilation error
2) equals ()
-only reference types can be compared, with the same effect as "= =", whether the comparison points to the same object
-When comparing with the Equals () method, it is the comparison type for the class File, String, Date, and wrapper class (Wrapper Class), and the content two does not consider whether the reference is the same object, because they override the Equals () method
java_day03 Java Basics