标签:控制台 img system ide 租房 ati stat sys static
package com.hpy.test; /** * 房东 */ public interface Landlord { public void house(); }
package com.hpy.test; /** * 房东A */ public class LandlordA implements Landlord{ public void house(){ System.out.println("房东A出租美丽沙三室一厅房子"); } }
package com.hpy.test; /** * 房东B */ public class LandlordB implements Landlord { public void house(){ System.out.println("房东B出租西海岸三室一厅房子"); } }
package com.hpy.test; /** * 中介 */ public class Intermediary implements Landlord { private Landlord landlord; public Intermediary(Landlord landlord){ this.landlord = landlord; } @Override public void house() { landlord.house(); } }
package com.hpy.test; /** * 房客 */ public class Client { public static void main(String[] args) { new Intermediary(new LandlordA()).house(); new Intermediary(new LandlordB()).house(); } }
控制台打印:
标签:控制台 img system ide 租房 ati stat sys static
原文地址:https://www.cnblogs.com/ithfm/p/9565512.html