您的位置:首页 > 编程语言 > Java开发

Java 方法的作用域中的内部类(不是在“外部类”的作用域中,当然,此处也没有相对的外部类)

2016-07-16 21:51 435 查看
interface Contents{
int value();
}

interface Destination{
String readLabel();
}

public class Parcel3 {
public Destination dest(String s){
class PDestination implements Destination{
private String label;
private PDestination(String whereTo){
label = whereTo;
}
public String readLabel(){
return label;
}
}
return new PDestination(s);
}

public static void main(String[] args) {
// TODO Auto-generated method stub
Parcel3 p = new Parcel3();
Destination d = p.dest("lalala");
System.out.println(d.readLabel());
}
}


上例中PDestination类即是方法dest中的内部类。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: