下面的程序中,哪行会报错?
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();
}
}
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();
}
}
举一反三
- 下面的程序中,哪行会报错? 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 StaticTest { ....showTotalFee(); } }
- 下列选项中,循环会无限执行的是______。 A: int i = 1 ; while ( i < 10) System .out .print( “ ” + i) ; B: for( int i = 1 ; i < 10 ;i ++) System .out .print( “ ” + i); C: for( int i = 10 ; i > 0 ;i --) System .out .print( “ ” + i); D: int i = 1 ; while (true) { System .out .print( “ ” + i); i ++ ; if ( i > 5) break ;
- 给定下面的代码片段: 哪些行会导致错误? () A: line 1 B: line 2 C: line 5 D: line 8
- 下列程序的运行结果是()。 public class Test public static void main ( String [ ] args ) int count = 0 for( int i = 1 i < 5 i = 2) for( int j = 1 j< = 10 j = 3) count System .out .print (count ) _