下面的程序中,哪行会报错? 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 Increment{ public static void main(String args[]) { int a; a = 6; System.out.print(a); System.out.print(a++); System.out.print(a); } }
- 以下代码执行后的结果是: public class Person { String name = “小芳”; public Person(String name) { name = “小兰”; } public void show() { this.name = “小翠”; } public static void main(String[] args) { Person p = new Person(“小凤”); System.out.print(p.name); p.show(); System.out.print(p.name); } }
- 下面的程序中,哪行会报错? 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(); } }
- 以下哪个是有效的Java程序入口函数? A: public static void main(String[] args); B: public static void main(); C: public static int main(String[] args); D: public static void main(int argc, String[] args)
- public class test { public static void main(String args[]) { int m=0; for ( int k=0;k<2;k++) method(m++); System.out.println(m); } public static void method(int m) { System.out.print(m); } }