这个是我曾经做的一个测试用例,运行没有问题:
class StaticInnerClass {
public StaticInnerClass() {
}
public static void main(String[] args) {
Parcel1 p = new Parcel1();
Contents1 c = p.cont();
c = new Parcel1.PContents1();
// c = p.new PContents();
c = Parcel1.cont1();
}
}
interface Contents1 {
int value();
}
class Parcel1 {
protected static class PContents1 implements Contents1 {
public int value() {
return 1;
}
}
public Parcel1() {
}
public Contents1 cont() {
//non-static method using new to generate static inner class object
return new PContents1();
}
public static Contents1 cont1() {
System.out.println("test");
//static method using new to generate static inner class object
return new PContents1();
}
public static void test(String[] args) {
Parcel1 p = new Parcel1();
Contents1 c = p.cont();
// c = p.new PContents();
c = new PContents1();
}
}
一个JAVA文件中如果有public标识类,main函数要写在public类中才有作用,因为你执行类时实际就是执行public类,如果它没有main的话就会抛出
Exception in thread "main" java.lang.NoSuchMethodError: main
这样的异常了.
你可以这样用这样的命令执行>java myclass_ex