interface CityNumber{//定义两个接口 int getNumber(); } interface Destination{ String getName(); } public class Main{ public class Citys implements CityNumber{//嵌套的内部类1 private int id=518; @Override public int getNumber() {//实现接口方法 return id; } } public class Cdest implements Destination{ private String label; private Cdest(String where)//传入一个地址 { label=where; } @Override public String getName() {//进行返回构造接口方法 return label; } } public CityNumber getID(){//构造方法返回接口1的对象 return new Citys(); } public Destination dest(String s)//返回接口2的对象 { return new Cdest(s); } public static void main(String[]args) { Main p=new Main(); CityNumber c=p.getID(); Destination d=p.dest("lianyung"); System.out.println(d.getName()+"|"+c.getNumber()); } }
标签:CityNumber,return,String,自定义,Destination,接口,嵌套,public From: https://www.cnblogs.com/liliczw2209/p/17307754.html