java 父类和子类

public class ren {

    private double height;
    private double weight;
    public double getHeight() {
        return height;
    }
    public void setHeight(double height) {
        this.height = height;
    }
    public double getWeight() {
        return weight;
    }
    public void setWeight(double weight) {
        this.weight = weight;
    }
    
    //打招呼
    public void sayhello()
    {
        System.out.println("hello");
    }
}
package lianxiti;

//extends 继承
//object是所有类的 父类。
public class chinaren extends ren 
{
    public void KongFu()
    {
        System.out.println("功夫很吊");
    }
    
    //重写  覆盖
    public void sayhello()
    {
        System.out.println("你好");
    }

    
}
package lianxiti;

public class textRen {

    public static void main(String[] args) {
        ren r1 = new ren();
        r1.sayhello();
        
        chinaren r2 = new chinaren();
        r2.sayhello();
        
        r2.setHeight(180);
        r2.setWeight(70);
        
        r2.KongFu();
        
        

    }

}

posted @ 2016-05-23 10:41  ╄承诺、带给的伤痛—  阅读(130)  评论(0编辑  收藏  举报