This is just one thing to remember, any property of the parent class (the variable can be considered a property), the subclass can inherit and overwrite,Alltype (father)-"Changeanytype (son)--" AnyType
This is all the delegate properties of the parent class (which I can think of), including ordinary instance variables, modifiers, access permissions, data types, constant modifiers, static modifiers
Package extendvariable;
Packageextendvariable; Public classAncestor {//Parent Class intix=0;//Normal instance member properties DoubleDX = 1;//instance member variables of different types intbx=10000; Final intfy=2;//General Volume member properties Static intsz=3;//normal static member properties Private intPrivar = 4;//member properties for different permissions intDefVar = 5;//Default Permissions protected intProvar = 6; Public intPubvar = 7; }
Subclasses inherit the parent class through extend by changing the related property
Packageextendvariable; Public classSonextendsancestor{//Change int to double, change double to int, type int to Boolean DoubleIX = 0.1; intDX = 10; Booleanbx=true; //change ordinary constant variable to normal variable intFY = 20; //to change a static member variable to a normal instance member variable intSz=30; //turn all permissions upside down. Public intPrivar=40; protected intDefvar=50; intProvar=60; Private intPubvar=70; Public voidShowallmember () {System.out.println ("Ix=" + This. ix); System.out.println ("Dx=" + This. DX); System.out.println ("Bx=" + This. BX); System.out.println ("Fy=" + This. FY); System.out.println ("Sz=" + This. SZ); System.out.println ("Privar=" + This. Privar); System.out.println ("Defvar=" + This. DefVar); System.out.println ("Provar=" + This. Provar); System.out.println ("Provar=" + This. Pubvar); } Public Static voidMain (String args[]) {son OA=Newson (); Oa.showallmember (); } }
The results are as follows:
ix= 0.1
dx= 10
bx= true
fy= 20
sz= 30
Privar= 40
Defvar= 50
This shows that any property of the parent class can be inherited and overwritten by the quilt class
About Java Inheritance Properties