首页 > 代码库 > 初始多态

初始多态

package Li;

public class Person {
String name;



public Person() {
    super();
}



public Person(String name) {
    super();
    this.name = name;
}



public void eat(){
    System.out.println(name+"正在吃面包");
}
}







package Li;

public class Student extends Person {

    public Student(String name) {
        super(name);
    
    }
public void eat(){
    System.out.println(this.name+"正在食堂吃早点");
}
    
    
    
    
}








package Li;

public class Famer extends Person  {

    public Famer(String name) {
        super(name);
        // TODO Auto-generated constructor stub
    }

public void eat(){
    System.out.println("我是农民"+name+"正在吃西瓜");
}
}








package Li;

public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
Person p;
p=new Student("李华");
p.eat();        


p=new Famer("袁隆平");
p.eat();


p=new Person("雷锋");
p.eat();

    }
    }

 

初始多态