/**
*猫、狗、青蛙
*
*/
public abstract class Animal {
String name;
//无参构造方法
public Animal(String name){
this.name=name;
}
//抽象方法
public abstract void say();//动物说话
public abstract void sayHello();//打招呼
public abstract void leg();//腿
}
package cn.xtgj.animal;
public interface FrogInterface {
public void fertility();
}
package cn.xtgj.animal;
/**
*猫类
*
*/
public class Cat extends Animal{
public Cat(String name){
super(name);
}
public void say() {
System.out.println(name+"是哺乳动物");
System.out.println(name+"是肉食动物");
}
public void sayHello() {
System.out.println(name+"通常的情况下,和人打招呼的方式为:喵喵叫");
System.out.println(name+"情绪好的时候会:咕噜咕噜叫");
System.out.println(name+"烦躁的时候,会:嘶嘶叫");
}
public void leg() {
System.out.println(name+"有四条腿");
}
}
package cn.xtgj.animal;
/**
* 狗类
*/
public class Dog extends Animal{
public Dog(String name){
super(name);
}
public void say() {
System.out.println(name+"是哺乳动物");
System.out.println(name+"是肉食动物");
}
public void sayHello() {
System.out.println(name+"通常的情况下,和人打招呼的方式为:摇摇尾巴");
System.out.println(name+"被抚摸情绪好的时候,打招呼的方式是:汪汪..汪叫");
System.out.println(name+"烦躁的时候,会:呜呜叫");
}
public void leg() {
System.out.println(name+"有四条腿");
}
}
package cn.xtgj.animal;
/**
*
*青蛙类
*/
public class Frog extends Animal implements FrogInterface{
public Frog(String name) {
super(name);
}
public void say() {
System.out.println(name+"不是哺乳动物");
System.out.println(name+"不是肉食动物");
}
public void sayHello() {
System.out.println(name+"通常的情况下,打招呼的方式为:呱呱呱...");
System.out.println(name+"情绪好的时候会:呱呱呱...");
System.out.println(name+"受到惊吓是会:扑通一声跳入水中");
}
public void leg() {
System.out.println(name+"有腮");
System.out.println(name+"有四条腿");
}
public void fertility() {
System.out.println(name+"产卵");
}
}
package cn.xtgj.animal;
public class AnimalMain {
public static void main(String[] args) {
//创建对象
Dog dog=new Dog("狗");
Cat cat=new Cat("猫");
Frog frog=new Frog("青蛙");
//狗
dog.say();//说话
dog.sayHello();//打招呼
dog.leg();//几条腿
System.out.println();
//猫
cat.say();//说话
cat.sayHello();//打招呼
cat.leg();//几条腿
System.out.println();
//青蛙
frog.say();//说话
frog.sayHello();//打招呼
frog.fertility();//生育方式
frog.leg();//几条腿
}
}