【发布时间】:2014-09-29 12:00:05
【问题描述】:
我试图了解我在使用此代码时做错了什么,但我没有找到答案。为什么它不会在编译器中打印任何内容?
请帮忙。提前致谢。
public class ClassA {
int x = 0;
int y = 1;
public void methodA() {
System.out.println( "x is " + x + " , and y is " + y) ;
System.out.println( "I am an instance of: " + this.getClass().getName() ) ;
}
}
class ClassB extends ClassA {
int z = 3;
public static void main(String[] args) {
ClassB obj1 = new ClassB();
obj1.methodA();
}
}
【问题讨论】:
-
Why it does not print anything in the compiler?因为编译器编译代码。您需要运行它才能看到输出。 -
@TheLostMind 不,这不是必需的。
-
您期待什么,实际发生了什么?您的问题不清楚。
-
因为编译器不认可您缺乏正确的格式。
-
@Kon - 正如问题所说,OP 并没有覆盖任何东西:)
标签: java