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

Posted hijackykun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();
    

 

以上是关于69期-Java SE-008_面向对象-2-001-002的主要内容,如果未能解决你的问题,请参考以下文章

69期-Java SE-009_面向对象-3-001-002

69期-Java SE-015_集合-1-001-002

69期-Java SE-016_集合-2-001-002

69期-Java SE-043_Servlet-1

69期-Java SE-004_循环数组-001-002

69期-Java SE-045_JSP-2