下面的程序中,哪行会报错? public class StaticTest { ....showTotalFee(); } }
举一反三
- 下面的程序中,哪行会报错? public class StaticTest { int age; String name; static int totalFee = 500; public void showName() { System.out.print(this.name); } public static void showTotalFee() { line 1: System.out.print(totalFee); line 2: showName(); } public static void main(String[] args) { line3: StaticTest.showTotalFee(); } }
- 下面程序的运行结果是public class Demo { public static void main(String[] args) { new Object(){ public void show(){ System.out.println("helloworld"); } }.show(); }} A: 什么也不输出 B: helloworld C: 编译报错 D: 编译通过,运行报错
- 下列的程序的运行结果是( )public class Example { public static void main(String[] args) { new Father () { public void show() { System.out.println("helloworld"); } }.show(); }}class Father { public void show() { System.out.println("hellofather"); }} A: hellofather B: helloworld C: 编译报错 D: 编译通过,运行报错
- 下面程序段中不正确的是( )。 A: package myPackage;public class A{} B: package myPackage; class B{ } C: package myPackage; import java.io.*; public class C{ } D: import java.awt.Color; package myPackage; class D{ }
- 下面的程序中,哪行会报错? publicclassStaticTest{ intage; Stringname; staticinttotalFee=500; publicvoidshowName(){ System.out.print(this.name); } publicstaticvoidshowTotalFee(){ line1:System.out.print(totalFee); line2:showName(); } publicstaticvoidmain(String[]args){ line3:StaticTest.showTotalFee(); } }