我正在尝试一些代码以更好地理解访问修饰符。我只添加了一行代码后一切都运行良好
class SomeClass2 {
protected static void method4() { }
protected static int x=0;
}
class SomeClass3 extends SomeClass2{
int c=SomeClass2.x;
public void somemethod() //Everything was compiling fine until
{ //Until I added this method
SomeClass2.method4();
}
}
class DemoClass1{
public static void main(String[] parameters) {
SomeClass2 sc = new SomeClass2();
SomeClass3 sc1 = new SomeClass3();
sc.method4();
System.out.println(sc1.c);
sc1.somemethod();
}
}
我收到一个错误:Could not find or load main class DemoClass1
所有类都属于相同的目录和相同的包。环境变量也都设置好了。在我添加somemethod()
. 它编译得很好,但不运行。