单选题分析下列java代码  Class A{  Public static void main(String[] args){  Method(); }  Static void method(){ try{  System.out.println(“hello”) }finally{  System.out.println(“good-bye”); }  } }  编译运行后,输出结果是()A “hello”B “good-bye”C “hello”“good-bye”D 代码不能编译

题目
单选题
分析下列java代码  Class A{  Public static void main(String[] args){  Method(); }  Static void method(){ try{  System.out.println(“hello”) }finally{  System.out.println(“good-bye”); }  } }  编译运行后,输出结果是()
A

“hello”

B

“good-bye”

C

“hello”“good-bye”

D

代码不能编译


相似考题
更多“单选题分析下列java代码  Class A{  Public static void main(String[] args){  Method(); }  Static void method(){ try{  System.out.println(“hello”) }finally{  System.out.println(“good-bye”); }  } }  编译运行后,输出结果是()A “hello”B “good-bye”C “hello”“good-bye”D 代码不能编译”相关问题
  • 第1题:

    阅读下列代码段,选出该代码段的正确文件名( )。 class A { void methodl() { System.out.println("methodl in class A"); } } public class B { void method2() { System.out.println("method2 in class B"); } public static void main(String args[]) { System.out.println("main in class B"); } }

    A.A.java

    B.A.class

    C.B.class

    D.B.java


    正确答案:D
    解析:Java源程序文件是以.java为后缀的,Java字节码文件以.class为后缀,而且 Java源文件中只能有一个public类,该类的名字为源文件名,程序段中类B是以public修饰的,因此源程序文件名为B.java。

  • 第2题:

    阅读下列代码

    Public class Person{

    Static int arr[ ] = new int (10);

    Public static void main (String args ) {

    System.out.println(arr[9]);

    }

    }

    该代码运行的结果是

    A )编译时将产生错误

    B )编译时正确,运行时将产生错误

    C )输出 0

    D )输出空


    正确答案:C

  • 第3题:

    有下列程序段 public class fun { public static void main(String args[]) { char b[]="Hello,you"; b[5] = 0; System.out.println(s); } 执行此程序后,得到的输出结果是( )。

    A.Hello, you

    B.Hello0you

    C.Hello

    D.0


    正确答案:C
    解析:本题常见的错误答案是:字符数组b初始化后,得b[5]=',',执行b[5]=0后,用0代替b[5]中的','即可。最后输出整个字符串:Hello0you。下面是正确解答:在C++语言中规定以字符'\0'作为字符串结束标志,语句b[5]=0就相当于语句b[5]='\0',即在数组b的b[5]上加了字符串结束标志,故执行该语句后,数组中存放的内容变为Hello。

  • 第4题:

    对于下面一段代码的描述中,正确的是______。 public class ex36 { public static void run main(String[] args) throws Excepion { method(); } static void method() throws Exception try { System.out.println("test"); } finally { System.out.println ("finally"); } } }

    A.代码编译成功,输出“test”和“fmally”

    B.代码编译成功,输出“test”

    C.代码实现选项A中的功能,之后Java停止程序运行,抛出异常,但是不进行处理

    D.代码不能编译


    正确答案:A

  • 第5题:

    编译和运行以下代码的结果为:public class MyMain{public static void main(String argv){System.out.println("Hello cruel world");}}

    A.编译错误;

    B.运行输出 "Hello cruel world";

    C.编译无错,但运行时指示没有定义构造方法。

    D.编译无错,但运行时指示没有正确定义main方法。


    正确答案:D

  • 第6题:

    分析下列代码:  Class A{  Public static void main(String[] args){  method(); }  static void method(){  try{  System.out.println("Hello"); }finally{  System.out.println("good-bye"); } } }  编译运行后,输出结果是()。 

    • A、"Hello"
    • B、"good-bye"
    • C、"Hello""god-bye"
    • D、代码不能编译

    正确答案:C

  • 第7题:

    class A {  public A() {  System.out.println(“hello from a”);  }  }  class B extends A {  public B () {  System.out.println(“hello from b”);  super();  }  }  public class Test {  public static void main(String args[]) {  A a = new B();  }  }   What is the result when main is executed?()  

    • A、 Compilation fails.
    • B、 hello from a
    • C、 hello from b
    • D、 hello from b hello from a
    • E、 hello from a hello from b

    正确答案:A

  • 第8题:

    考虑下列Java代码:  class A {  public static void main(String[] args) {    try {  System.out.println("Hello, World!");  }  } }  其中的错误是()。 

    • A、没有catch或finally块
    • B、没有抛出异常的代码不能出现在try代码块内
    • C、如果没有catch块而使用try,main()会总是抛出异常.
    • D、class A 没有throws IOException

    正确答案:A

  • 第9题:

    现有:     class Pencil  {  public void write (String content){     System.out.println ("Write"+content);     }     }  class RubberPencil extends Pencil{     public void erase (String content){     System.out.println ("Erase"+content);     }     }  执行下列代码的结果是哪项?()      Pencil pen=new RubberPencil();      pen.write ("Hello");      pen.erase ("Hello");    

    • A、 Write Hello        Erase Hello
    • B、 Erase Hello        Write Hello
    • C、编译错误
    • D、运行时抛出异常

    正确答案:C

  • 第10题:

    单选题
    分析下列Java代码:   class A {  public static void main(String[] args)    {   method();   }      static void method()    {     try    {  System.out.println("Hello");    System.exit(0);    }    finally   {  System.out.println("good-bye");  }   }    }  编译运行后,输出结果是()。
    A

    Hello

    B

    good-bye

    C

    Hello后面是good-bye

    D

    代码不能编译


    正确答案: A
    解析: 暂无解析

  • 第11题:

    单选题
    考虑下列Java代码: Classc A{  Public static void main(String []args){ Try{  System.out.println(“hello,world”) } }  } 其中错误的是()。
    A

    没有catch或finally块

    B

    没有抛出异常的代码不能出现在try代码块内

    C

    如果没有catch块而使用try,main()会总是抛出异常.

    D

    class A 没有throws IOException


    正确答案: D
    解析: 暂无解析

  • 第12题:

    单选题
    考虑下列Java代码:  class A {  public static void main(String[] args) {    try {  System.out.println("Hello, World!");  }  } }  其中的错误是()。
    A

    没有catch或finally块

    B

    没有抛出异常的代码不能出现在try代码块内

    C

    如果没有catch块而使用try,main()会总是抛出异常.

    D

    class A 没有throws IOException


    正确答案: A
    解析: 暂无解析

  • 第13题:

    阅读下列代码段,选出该代码段的正确文件名( )。 class A { void method1() { System.out.println("method1 in class A"); } } public class B { void method2() { System.out.println("method2 in class B"); } public static void main(String args[]) { System.out.println("main in class B"); } }

    A.A.java

    B.A.class

    C.B.class

    D.B.java


    正确答案:D
    解析:Java源程序文件是以Java为后缀的,Java字节码文件以.class为后缀,而且 Java源文件中只能有一个public类,该类的名字为源文件名,程序段中类B是以public修饰的,因此源程序文件名为Biava。

  • 第14题:

    请在下划线处填入代码,是程序正常运行并且输出 “ Hello! ”

    Class Test 【 15 】 {

    Public static void main (String[] arge){

    Test t = new Test();

    t.start();

    }

    Public void run(){

    System.out.println( “ Hello! ” );

    }


    正确答案:

  • 第15题:

    阅读下列代码段,选出该代码段的正确的文件名( )。 class A { void method () { System.out.println ("methodl in class A"); } } public class B { void method2 () { System.out.println("method2 in class B"); } public static void main (String args[]) { System.out.println ("main () in class B"); } }

    A.A.java

    B.A.class

    C.B.class

    D.B.java


    正确答案:D
    解析:Java源文件以.java为后缀,Java字节码文件以.class为后缀。Java源文件中只有一个public的类,该类的名字为源文件名,这里类B是以public修饰的,因此源文件名为B.java。

  • 第16题:

    下列程序的输出结果是( )。 public class Test { public static void main (String[] args) { String s="hello"; s.replace ('r','m'); System.out.println(s); } }

    A.hello

    B.HELLO

    C.hemmo

    D.HEMMO


    正确答案:A
    解析:String类的replace (char oldChar,char newChar)函数的作用是返回一个新的字符串,它是通过用newChar替换此字符串中出现的所有oldChar而生成的。返回的是新字符串,但是原字符串变量的值并未发生改变。因此,输出的是“hello”而不是“hemmo”。如果替换语句换为: s=s.replace('l','m');,则输出“hemmo”。

  • 第17题:

    以下代码的输出结果?public class Test{public static void main(String argv[]){String x="hello";change(x);System.out.println(x);}static void change(String m){m=m+2;}}

    A. hello

    B. hello2

    C. 编译报错

    D. 运行报错,不能将串与整数相加


    正确答案:A

  • 第18题:

    考虑下列Java代码: Classc A{  Public static void main(String []args){ Try{  System.out.println(“hello,world”) } }  } 其中错误的是()。 

    • A、没有catch或finally块
    • B、没有抛出异常的代码不能出现在try代码块内
    • C、如果没有catch块而使用try,main()会总是抛出异常.
    • D、class A 没有throws IOException

    正确答案:B

  • 第19题:

    分析下列Java代码:   class A {  public static void main(String[] args)    {   method();   }      static void method()    {     try    {  System.out.println("Hello");    System.exit(0);    }    finally   {  System.out.println("good-bye");  }   }    }  编译运行后,输出结果是()。     

    • A、"Hello"
    • B、"good-bye"
    • C、"Hello"后面是"good-bye"
    • D、代码不能编译

    正确答案:A

  • 第20题:

    分析下列java代码  Class A{  Public static void main(String[] args){  Method(); }  Static void method(){ try{  System.out.println(“hello”) }finally{  System.out.println(“good-bye”); }  } }  编译运行后,输出结果是()

    • A、“hello”
    • B、“good-bye”
    • C、“hello”“good-bye”
    • D、代码不能编译

    正确答案:C

  • 第21题:

    单选题
    下列程序的运行结果是(  )。class Test extends Thread{  public static void main(String[] args)  {    Thread t=new Thread();    t.start();  }  public void run()  {    System.out.println("Hello");  }}
    A

    程序不能通过编译,因为没有import语句将Thread类引入

    B

    程序不能通过编译,因为Test类没有实现Runnable接口

    C

    程序通过编译,且运行正常,没有任何输出

    D

    程序通过编译,且运行正常,打印出一个"Hello"


    正确答案: C
    解析:
    此程序继承了Thread,同时也有run方法,符合线程的创建规则,但是在创建线程对象时,所使用的的类为Thread,此处所创建对象毫无意义,不会运行任何结果,应该创建Test的对象,所以该程序会通过编译,且运行正常,但是没有任何输出。

  • 第22题:

    单选题
    分析下列代码:  Class A{  Public static void main(String[] args){  method(); }  static void method(){  try{  System.out.println("Hello"); }finally{  System.out.println("good-bye"); } } }  编译运行后,输出结果是()。
    A

    Hello

    B

    good-bye

    C

    Hellogod-bye

    D

    代码不能编译


    正确答案: A
    解析: 暂无解析

  • 第23题:

    单选题
    class A {  public A() {  System.out.println(“hello from a”);  }  }  class B extends A {  public B () {  System.out.println(“hello from b”);  super();  }  }  public class Test {  public static void main(String args[]) {  A a = new B();  }  }   What is the result when main is executed?()
    A

     Compilation fails.

    B

     hello from a

    C

     hello from b

    D

     hello from b hello from a

    E

     hello from a hello from b


    正确答案: D
    解析: Call to super must be first statement in constructor.