0
点赞
收藏
分享

微信扫一扫

简单类的继承(二)

sunflower821 2023-04-12 阅读 72


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

举报

相关推荐

0 条评论