• 69期-Java SE-008_面向对象-2-001-002


     

     

     

     

     

     

     ------------------

     

     --------------

     

     

     

     

    User.java

    public class User {
        public static String name;
        public static int num;
        static {
            num++;
            System.out.println("执行了静态代码块");
        }
        static {
            System.out.println("static2");
        }
    }

    Cashier.java

    package entity;
    
    public class Cashier {
        private Member member;
        
        public Member getMember() {
            return member;
        }
    
        public void setMember(Member member) {
            this.member = member;
        }
    
        public void settlement() {
            this.member.buyBook();
        }
    }

    Member.java

    package entity;
    
    public class Member {
        public void buyBook() {
            
        }
    }

    OrdinaryMember.java

    package entity;
    
    public class OrdinaryMember extends Member {
        
        @Override
        public void buyBook() {
            System.out.println("普通会员买书打9折");
        }
    }

    People.java

    package entity;
    
    public class People {
        public void show() {
            System.out.println("输出人员信息");
        }
        
        private    People getPeople() {
            return new People();
        }
    }

    Student.java

    package entity;
    
    public class Student extends People {
        @Override
        public void show() {
            // TODO Auto-generated method stub
            System.out.println("这是一个学生");
        }
        
    }

    SuperMember.java

    package entity;
    
    public class SuperMember extends Member {
        
        @Override
        public void buyBook() {
            System.out.println("超级会员买书打6折");
        }
    }

    Teacher.java

    package entity;
    public class Teacher extends People {
        @Override
        public void show() {
            // TODO Auto-generated method stub
            System.out.println("这是一个老师");
        }
    }

     

     

    Test.java

    package entity;
    
    public class Test {
        public static void main(String[] args) {
            OrdinaryMember ordinaryMember = new OrdinaryMember();
            SuperMember superMember = new SuperMember();
            Cashier cashier = new Cashier();
            cashier.setMember(superMember);
            cashier.settlement();
        }
    }
  • 相关阅读:
    EKLM3S8962之LED
    [uClinuxdev] detecting stack overflow
    Eclipse换行符
    EKLM3S8962之OLED
    Windows 环境下 GNU ARM 开发环境建立
    关于阻焊层和助焊层的理解
    MISRA C 2004中文版
    对话框托盘程序实现源码
    VC++中四种进程或线程同步互斥的控制方法
    Windows线程同步与互斥技术总结
  • 原文地址:https://www.cnblogs.com/HiJackykun/p/11172117.html
Copyright © 2020-2023  润新知