• 2022-06-11
    分析下述代码,下列描述正确的是()。public class Test { public static void main(String[] args) { double radius; final double PI= 3.15169; double area = radius * radius * PI; System.out.println("Area is " + area); }}
    A: 程序有编译错误,因为变量半径未初始化。
    B: 程序编译并运行良好。
    C: 程序没有编译错误,但会出现运行时错误,因为radius未初始化。
    D: 程序有编译错误,因为在方法中定义了常量PI。
  • A

    举一反三

    内容

    • 0

      代码如下: public class Foo{ public static void main(String args[]){ String s; System.out.println("s="+s); } } 下列关于程序编译运行的说法正确的是: A: 程序编译正确,并输出: “s=” 。 B: 程序编译正确,并输出: “s=null”。 C: 程序编译错误,因为变量s未被初始化。 D: 程序编译正确,但运行时抛出空指针异常。

    • 1

      阅读下面程序,程序的运行结果是( )。public class Example {public static void main(String[] args) {int area = getArea(3, 5);System.out.println(" The area is " + area);}public static int getArea(int x, int y) {int temp = x * y; return temp; }} A: 编译错误 B: The area is 3 C: The area is 5 D: The area is 15

    • 2

      分析下列代码:[br][/br] public class Test { public static void main(String[ ] args) { int[ ] x = new int[3]; System.out.println("x[0] is " + x[0]); } } A: 程序运行正常,显示x[0]为0。 B: 程序有一个运行时错误,因为数组元素没有初始化。 C: 由于未定义数组元素x[0],程序出现运行时错误。 D: 程序有一个编译错误,因为在声明数组时未指定数组的大小。

    • 3

      (多线程的两种实现方法)阅读下面程序:class Test implements Runnable{ public static void main(String[] args){ Test t=new Test(); t.start(); } public void run(){} }下列关于上述程序的叙述正确的是_______。 A: 程序不能通过编译,因为start()方法在Test类中没有定义 B: 程序编译通过,但运行时出错,提示start()方法没有定义 C: 程序不能通过编译,因为run()方法没有定义方法体 D: 程序编译通过,且运行正常

    • 4

      程序Helloworld.java编译错误。( )public class HelloWorld { public static void main(String[] args){ system.out.println("Hello World!"); } }