简单类的继承(二)

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
    */
 }
 
}



欢迎关注公众号:Java后端技术全栈