- class Noname1 {
- public static void main(String[] args) {
- Cat cat = new Cat("罗小黑",250);
- cat.job();
- cat.eat();
- cat.jump();
- Dog dog = new Dog("菜包狗",100);
- dog.job();
- dog.eat();
- JumpDog jdog = new JumpDog("高斯",400);
- jdog.jump();
- }
- }
- interface Jump {
- public void jump();
- }
- abstract class Animal {
- String name;
- int age;
- Animal() {};
- Animal(String name,int age) {
- this.name = name;
- this.age = age;
- }
-
- public void setName() {
- this.name = name;
- }
- public String getName() {
- return name;
- }
- public void setAge() {
- this.age = age;
- }
- public int getAge() {
- return age;
- }
- public String getname(String name) {
- return name;
- }
- abstract void eat();
- abstract void job();
- }
- class Cat extends Animal implements Jump {
- Cat(String name,int age) {
- super(name,age);
- }
- void job() {
- System.out.println(this.name+"捉老鼠");
- }
-
- void eat() {
- System.out.println(this.name+"吃鱼");
- }
-
- public void jump() {
- System.out.println(this.name+"跳高");
- }
- }
- class Dog extends Animal {
- Dog(String name,int age) {
- super(name,age);
- }
-
- void eat() {
- System.out.println(this.name+"吃大白兔");
- }
- void job() {
- System.out.println(this.name+"看门");
- }
- }
- class JumpDog extends Dog implements Jump {
- JumpDog(String name,int age) {
- super(name,age);
- }
- public void jump() {
- System.out.println(this.name+"跳高");
- }
- }
复制代码 |
|