• 2022-06-18
    阅读下面的程序,分析代码是否能够编译通过,如果能编译通过,请列出运行的结果,否则请说明编译失败的原因。Class Demo{ public static void main(String args){ if(true){ int x = 0 ; x ++ ; } System.out.println(x); }}
  • 编译失败,因为变量x的作用域是在if大括号中,在if大括号以外使用该变量,超过了变量的作用范围

    举一反三

    内容

    • 0

      阅读下面的程序, 分析代码是否能够编译通过,如果能编译通过,请列出运行的结果。 否则请说明编译失败的原因。class A {private int secret = 5;}public class Test1 {public static void main(String[] args) {A a = new A();System.out.println(a.secret++);}}

    • 1

      阅读下面的程序,分析代码是否能够编译通过,如果能编译通过,请列出运行的结果。否则请说明编译失败的原因。public class Test04 {public static void main(String args[]) {int n = 9;while (n >; 6) {System.out.println(n);n--;}}}

    • 2

      56.请阅读下面的程序,分析代码是否能够编译通过,如果能编译通过,请列出运行的结果,否则请说明编译失败的原因。 Public class DoWhileDemo1 { public static void main(String[] args) { int n = 1; int m = 5; do { System.out.println(n); n++; } while (n == m); } }

    • 3

      阅读下面的程序,分析代码是否能够编译通过,如果能编译通过,请列出运行的结果。否则请说明编译失败的原因。 代码一: class A { private int secret = 5; } class Test1 { public static void Main(string[] args) { A a = new A(); Console.WriteLine(a.secret++); Console.ReadKey(); } }

    • 4

      阅读下面的程序,分析代码是否能编译通过。如果能编译通过,请列出运行的结果;如果不能编译通过,请说明原因。class RunHandler {public void run() {System.out.println("run");}}public class Read01 {public static void main(String [] args) {Thread t = new Thread(new RunHandler( ));t.start( );}}