码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-07-11 20:38:59      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:rri   eth   int   string   超级   extends   show   void   java   

 

 

技术图片

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();
    }
}

 

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

标签:rri   eth   int   string   超级   extends   show   void   java   

原文地址:https://www.cnblogs.com/HiJackykun/p/11172117.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!