1.20作业

父类

package com.hanqi;


public class father {
    public father (){
        //System.out.println("父类的构造函数");
    }
     private String x1;
     
     private String x2;
     
     public String getX1() {
       return x1;
     }
     public void setYuyin(String x1) {
         this.x1 = x1;
     }
     public String getX2() {
         return x2;
     }
     public void setYuhui(String x2) {
         this.x2 = x2;
     }
    
     void   y1()
     {
         System.out.println("方法一");
     }
     void y2()
     {
         System.out.println("方法二");
     }

}

子类覆盖

package com.hanqi;

public class Son extends father {
    public Son()
    {
        System.out.println("子类构造函数");
    }
    public void y2()
    {
        System.out.println("子类重写方法");
    }

    
    
}

 

向上转型

 

package com.hanqi;

public class ceshi2 {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
          Son zl = new Son();
            
            zl.y1();
            
            zl.y2();
            
           father fl = new father();
           
           fl.y1();
           
           fl.y2();
    }

}

posted @ 2016-01-20 20:15  梦里梦到梦  阅读(184)  评论(0编辑  收藏  举报