69期-Java SE-008_面向对象-2-001-002
2020-12-13 06:15
标签:rri eth int string 超级 extends show void java User.java Cashier.java Member.java OrdinaryMember.java People.java Student.java SuperMember.java Teacher.java Test.java 69期-Java SE-008_面向对象-2-001-002 标签:rri eth int string 超级 extends show void java 原文地址:https://www.cnblogs.com/HiJackykun/p/11172117.htmlpublic class User {
public static String name;
public static int num;
static {
num++;
System.out.println("执行了静态代码块");
}
static {
System.out.println("static2");
}
}
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();
}
}
package entity;
public class Member {
public void buyBook() {
}
}
package entity;
public class OrdinaryMember extends Member {
@Override
public void buyBook() {
System.out.println("普通会员买书打9折");
}
}
package entity;
public class People {
public void show() {
System.out.println("输出人员信息");
}
private People getPeople() {
return new People();
}
}
package entity;
public class Student extends People {
@Override
public void show() {
// TODO Auto-generated method stub
System.out.println("这是一个学生");
}
}
package entity;
public class SuperMember extends Member {
@Override
public void buyBook() {
System.out.println("超级会员买书打6折");
}
}
package entity;
public class Teacher extends People {
@Override
public void show() {
// TODO Auto-generated method stub
System.out.println("这是一个老师");
}
}
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
文章链接:http://soscw.com/essay/32771.html