面向对象

package lianxi;

public class Lianxi extends Dog {

    private String name;
    
    private int age;
    
    public void run() {
        
    }
    
    public String getName(){
        return name;
        
    }
    public void setName(String name) {
        this.name = name;
    }
    
    
    
    public boolean equals(Object obj) {
        if (obj == null){
            return false;
        }
        if (obj == this) {
            return true;
        }
        Dog other = (Dog)obj;
        if (other.getName().equals(this.getName())) {
            return true;
        }
        return false;
            
    }
    //@Override
    public String toString2() {
        return "Dog [ age = " + this.getAge() + " ] ";}    
    public static void main(String[] args) {
        
    }
    

}
package lianxi;

public class Dog extends Object {
        private int age;
        
        private String name;
        public String getName(){
            return name;
            
        }
        public void setName(String name) {
            this.name = name;
        }
        
        public int getAge() {
            return age;
        }
        
        public void setAge(int age) {
            this.age = age;
        }
        
        public void run() {
            System.out.println("动物在奔跑!");
        }

/*        public String toString2() {
            // TODO Auto-generated method stub
            return null;
        }*/
}

子承父级的重写。

posted @ 2018-05-04 16:32  峰栯  阅读(112)  评论(0编辑  收藏  举报