package collection;
class Father {
public Father() {
System.out.println("Father");
}
public void test() {
System.out.println("Father test");
}
}
class Son extends Father {
public Son() {
super();
System.out.println("Son");
}
public void test() {
System.out.println("Son test ");
}
}
public class MyExtends {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Son son = new Son(); // 此时打印出
son.test();
/*
* Father
* Son
* Son test
*/
Father father = new Father(); // 此时打印出
father.test();
/*
* Father
* Father test
*/
Father father2 = new Son();
father2.test();
/*
* Father
* Son
* Son test
*/
}
}