Java内部类问题,

zhudonhua zhudonhua 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
interface Destination
{
String readLabel();
}
class Parcel
{
public Destination dest(String s)
{
class PDestination implements Destination
{
private String label1;

private PDestination(String whereTo)
{
label1 = whereTo;
}
public String readLabel()
{
return label1;
}
}

return new PDestination(s);
}

public static void main(String[] args)
{
Parcel p = new Parcel();
Destination d = p.dest("Tanizania");
System.out.println(d.readLabel());
}

}

运行结果

Tanizania:

疑惑:

不是类的构造函数申明了private????怎么还可以生成对象??

具体见thinking in java(2E) P264



...全文
评论 18
收藏 已收藏
分享
返回顶部
zhudonhua
Java SE 62,620 成员 307,251 内容