简单类的继承(二)

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


猜你喜欢

转载自blog.51cto.com/10983206/2564403