zoukankan      html  css  js  c++  java
  • 接口,抽象类的一个demo

    #定义一个抽象类
    abstract class Ou {
            #成员变量
        private String name;
        private int age;
           #空参构造方法
        public Ou(){}  
           #有参构造方法
        public Ou(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 abstract  void eat();
        public abstract  void sleep();
    }
    
    #定义接口
    interface Jumping{
        public void jump();
    }
    
    
    #定义Mimi类继承抽象类Ou
    class Mimi extends Ou{
        public Mimi(){}
        public Mimi(String name,int age){
            super(name,age);
        }
        public  void eat(){
            System.out.println("猫吃饭");
        };
        public void sleep(){
            System.out.println("猫爱睡觉");
        }
    }
    
    
    #定义JumpCat继承Mimi类并实现Jumping接口
    class JumpCat extends Mimi implements Jumping{
        public JumpCat(){}
        public JumpCat(String name,int age){
            super(name,age);
        }
        public void jump(){
            System.out.println("猫跳高");
        }
    }
    
    
    public class Test_interFace {
        public static void main(String[] args){
            Mimi m = new Mimi("加肥",8);
            m.eat();
            m.sleep();
            
            
            JumpCat jc = new JumpCat("蛋黄",4);
            jc.eat();
            jc.jump();
            jc.sleep();
            
        }
    }    
  • 相关阅读:
    [NOI2007]生成树计数
    [NOI2009]变换序列
    BZOJ3261 最大异或和
    [SHOI2011]双倍回文
    [TopCoder14647]HiddenRabbits
    [HDU5709]Claris Loves Painting
    [BZOJ4559][JLOI2016]成绩比较
    [CF995F]Cowmpany Cowmpensation
    [TopCoder11557]MatrixPower
    [UOJ198][CTSC2016]时空旅行
  • 原文地址:https://www.cnblogs.com/Wly-blogs/p/9609271.html
Copyright © 2011-2022 走看看