为什么我分开来编译出错,合起来就行?
package c07.innerscopes;interface Destination {
String readLabel();
}
//
package c07.innerscopes;public class Parcel4 {
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) {
Parcel4 p = new Parcel4();
Destination d = p.dest("Mtan");
}
}
package c07.innerscopes;interface Destination {
String readLabel();
}
//
package c07.innerscopes;public class Parcel4 {
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) {
Parcel4 p = new Parcel4();
Destination d = p.dest("Mtan");
}
}
只要你在F:\MyDel\c07\innerscopes\ 这个路径下编译 跟执行就应该没问题。。
而分开编译与合在一起编译产生的问题,二楼的朋友说得也很正确了~
即是:
javac -classpath F:\MyDel\c07\innerscopes\ Parcel4.java