房天下 > 房天下问答 > 业主生活 > 其他
  • 急求java代码

    有一个Animal类,它里面定义了 void eat()、void breath( )两个方法,方法体的内容自己定义,从Animal类派生出Fish、Cat类,要求在main方法中有Fish、Cat类的对象调用父类Animal中的两个方法。

    提问者:sesameabc

    发布于2010-10-03

共1个回答
  • _宁菲儿 丨Lv 1
    /** * 测试类 * @author thinkpad * */public class AnimalTest { public static void main(String[] args) { Fish fish = new Fish(); fish.breath(); fish.eat(); Cat cat = new Cat(); cat.breath(); cat.eat(); }}/** * Animal类 * @author thinkpad * */class Animal { public void eat() { System.out.println(this.getClass().getSimpleName() + " is eating something."); } public void breath() { System.out.println(this.getClass().getSimpleName() + " is breathing."); }}/** * Fish类 * @author thinkpad * */class Fish extends Animal { }/** * cat类 * @author thinkpad * */class Cat extends Animal { }
    +1 2010-10-03 举报
热门人气推荐
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。