public class Father {
static {
Log.i("lsy", "Father static init");
}
{
Log.i("lsy", "Father class init");
}
Father() {
Log.i("lsy", "Father start initMethod");
initMethod();
Log.i("lsy", "Father finish initMethod");
}
public void initMethod() {
Log.i("lsy", "Father initMethod");
}
}
public class Son extends Father {
int aInt = 1;
String aString = "1111";
static String sString = "ccc";
static {
Log.i("lsy", "son static init");
Log.d("lsy", "static orign sString= " + sString);
}
{
Log.i("lsy", "son class init");
Log.d("lsy", "orign aInt= " + aInt);
Log.d("lsy", "orign aString= " + aString);
Log.d("lsy", "orign sString= " + sString);
}
public Son() {
super();
Log.i("lsy", "son init");
Log.d("lsy", "value aInt = " + aInt);
Log.d("lsy", "value aString = " + aString);
Log.d("lsy", "value sString = " + sString);
}
@Override
public void initMethod() {
super.initMethod();
Log.i("lsy", "son initMethod");
Log.d("lsy", "initD aInt= " + aInt);
Log.d("lsy", "initD aString= " + aString);
Log.d("lsy", "initD sString= " + sString);
}
}
Father static init
son static init
static orign sString= ccc
Father class init
Father start initMethod
Father initMethod
son initMethod
initD aInt= 0
initD aString= null
initD sString= ccc
Father finish initMethod
son class init
orign aInt= 1
orign aString= 1111
orign sString= ccc
son init
value aInt = 1
value aString = 1111
value sString = ccc
父类调用被子类重写的方法,可能引发空指针异常