- class Test_AnimalCatJumpCat {
- public static void main(String[] args) {
- JumpCat jc=new JumpCat("Miky",3);
- System.out.println(jc.getName()+"---"+jc.getAge());
- jc.jump();
- jc.show();
- }
- }
- abstract class Animal{
- private String name;
- private int age;
- public Animal(){}
- public Animal(String name,int age){
- this.name=name;
- this.age=age;
- }
- public void setName(String name){
- this.name=name;
- }
- public String getName(){
- return name;
- }
-
- public void setAge(int age){
- this.age=age;
- }
- public int getAge(){
- return age;
- }
- public void show(){
- System.out.println("NameIs"+name+"---"+"AgeIs"+age);
- }
- public abstract void eat();
- }
- interface Inter{
- public abstract void jump();
- }
- class Cat extends Animal{
- public Cat(){}
- public Cat(String name,int age){
- super(name,age);
- }
- public void eat(){
- System.out.println("CatEatFish");
- }
- }
- class JumpCat extends Cat implements Inter{
- public JumpCat(){}
- public JumpCat(String name,int age){
- super(name,age);
- }
- public void jump(){
- System.out.println("CatLearnJumping");
- }
- }
复制代码 |
|