1. Heterogeneous arrays
Polymorphism of the expression and double can directly convert int a=3;double to accept int b=a;
Animal dog=new Dog ();//Instantiate a Dog object modification before notice upward conversion
Down conversion//type Restore
instanceof determines the type of the attribute, which can be used to avoid type conversion exceptions.
D instanceof Dog, judging if D is not a dog type, if it is complete forced conversion of dog d= (dog) dog;
Different subclasses belonging to the same parent class:
Animal is the parent class of dog Cut
Animal dog=new Dog ();//Use a reference to the parent class to point to the instantiation of the child class.
Cut cut =new cut ();
Animal [] animal=new animal[2];
Animal[0]=dog;
Animal[1]=cut;
2. Rewrite
Overriding note that during the rewrite process, the access modifier can be enlarged, and the return value can be reduced;
Parent class Method:
Public Animal Lingyang (Animal d) {
return D;
}
Subclass Overrides:
Public Dog Lingyang (Animal d) {
Dog dong = (dog) D;
return dog;
}
3.8 Basic data types corresponding to the wrapper class
int-->integer;
double-->double;
float-->float;
byte-->byte;
boolean-->boolean;
short-->short;
long-->long;
char-->character;
int b=1;
Integer c=b;---------->//the process of converting a basic data type to a wrapper class is called boxing
Integer b=1;
int c=b;-----> unpacking;
The above are all small knowledge, * * *
Some embodiment of polymorphism in Java, rewriting and wrapper classes