public class Parcel11{
class Contents{
private int i = 11;
public int value(){
return i;
}
}
class Destination {
private String Label;
Destination(String whereTo){
Label = whereTo;
}
String readLabel(){
return Label;
}
}
public static void main(String[] args){
Parcel11 p = new Parcel11();
Parcel11.Contents c = p.new Contents();
Parcel11.Destination d = p.new Destination("Tanzania");
}
比如上面这个程序.书上说直接创建内部类的对象,必须得指明这个对象的类型OuterClassName.InnerClassName
可是我去掉Parcel11后,程序也能编译通过,难道书上说错了?
即 Contents c = p.new Contents();这样也是对的!
class Contents{
private int i = 11;
public int value(){
return i;
}
}
class Destination {
private String Label;
Destination(String whereTo){
Label = whereTo;
}
String readLabel(){
return Label;
}
}
public static void main(String[] args){
Parcel11 p = new Parcel11();
Parcel11.Contents c = p.new Contents();
Parcel11.Destination d = p.new Destination("Tanzania");
}
比如上面这个程序.书上说直接创建内部类的对象,必须得指明这个对象的类型OuterClassName.InnerClassName
可是我去掉Parcel11后,程序也能编译通过,难道书上说错了?
即 Contents c = p.new Contents();这样也是对的!
谁能帮我解释一下.
即 Contents c = p.new Contents();是对的