标签: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