abstract class Contents {
abstract public int value();
}
//接口 Destintion
interface Destination {
String readLabel();
} class Parcel3 {
//私有的内类继承抽象类contents
private class PContents extends Contents {
private int i = 11;
public int value() { return i; }
}
//内类实现接口
protected class PDestination
implements Destination {
private String label;
//注意这个构造器是私有的???????????????????????????????????
private PDestination(String whereTo) {
label = whereTo;
}
public String readLabel() { return label; }
}
//问题就是这个方法,他调用了PDestination(s)私有的构造器
public Destination dest(String s) {
return new PDestination(s); //构造器是私有的怎么可以new?
}
public Contents cont() {
return new PContents();
}
} class Test {
public static void main(String[] args) {
Parcel3 p = new Parcel3();
Contents c = p.cont();
Destination d = p.dest("Tanzania");
// Illegal -- can't access private class:
//! Parcel3.PContents c = p.new PContents();
}
}
为什么可以调用私有的构造器?
abstract public int value();
}
//接口 Destintion
interface Destination {
String readLabel();
} class Parcel3 {
//私有的内类继承抽象类contents
private class PContents extends Contents {
private int i = 11;
public int value() { return i; }
}
//内类实现接口
protected class PDestination
implements Destination {
private String label;
//注意这个构造器是私有的???????????????????????????????????
private PDestination(String whereTo) {
label = whereTo;
}
public String readLabel() { return label; }
}
//问题就是这个方法,他调用了PDestination(s)私有的构造器
public Destination dest(String s) {
return new PDestination(s); //构造器是私有的怎么可以new?
}
public Contents cont() {
return new PContents();
}
} class Test {
public static void main(String[] args) {
Parcel3 p = new Parcel3();
Contents c = p.cont();
Destination d = p.dest("Tanzania");
// Illegal -- can't access private class:
//! Parcel3.PContents c = p.new PContents();
}
}
为什么可以调用私有的构造器?
解决方案 »
- JAVA前一周每天时间的算法
- replaceAll()方法替换字符串中多个其它符号
- 怎样用JDBC获得数据库中所有的表名?
- !!!请问用话筒当声音用什么类,方法!!!!!!!!
- 一个日志文件过大,要如何读取,才可以保证不会出现内存溢出
- 关于Swing多线程问题 各位大侠请帮忙!!!
- 散分(2),祝大家新春愉快!回家前结贴。
- 文明始于禁忌——《高质量Java程序设计》
- jdbc中一个Connection对象可以连续生成多个Statement吗?
- java中将大写子母变为小写子母,并后退一位
- 如何在tomcat里设置,让打开我的项目有个登录窗口,就像打开http://localhost:8080/manager/html
- session.createSQLQuery为什么不能更新数据库???急
都可以在内部类中使用