第5题 设计Bird 、Fish类,都继承自抽象类Animal,实现其抽象方法info(),并输出他们的信息。
package com.homework.demo.test4_5;
/**
* 动物类
* @author suixin
*
*/
public abstract class Animal {
private int age; //年龄
/**
* 无参构造
*/
public Animal() {
super();
// TODO Auto-generated constructor stub
}
/**
* 带参构造
* @param age 年龄
*/
public Animal(int age) {
super();
this.age = age;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
/**
* 抽象输出信息方法
*/
public abstract void info();
}
package com.homework.demo.test4_5;
/**
* 鸟类
* @author suixin
*
*/
publ

本篇博客介绍了使用面向对象思想设计的Animal抽象类,以及其子类Bird和Fish的实现,详细阐述了如何通过封装和继承特性来描述家禽——鸡和鸭的信息。
最低0.47元/天 解锁文章
850

被折叠的 条评论
为什么被折叠?



