JAVA面向对象学习——java面向对象概念———一个简单的继承示例——super

 

public class Animal
{
    private String f_name;
    private int f_id;

    public Animal(String myName1, int myid1)
    {
        f_name = myName1;
        f_id = myid1;
    }

    public void eat()
    {
        System.out.println(f_name+" is  eat");
    }

    public void sleep()
    {
        System.out.println(f_name+" is  sleep");
    }

    public void introduction()
    {
        System.out.println("hello   , i'm  is  "         + f_id + "----" + f_name + ".");
    }
}

 

 

 

 

 

 

 

 

public class Penguin extends Animal
{
    public Penguin(String myName2, int myid2)
    {
        super(myName2, myid2);
    }

    public static void main(String[] args)
    {
        Animal am = new Animal("QI-E",111);

        am.eat();

        am.sleep();

        am.introduction();

    }

}

  

 

 

 

posted @ 2022-01-16 17:27  小白龙白龙马  阅读(37)  评论(0编辑  收藏  举报