JAVA面試題(1)

來源:互聯網
上載者:User

標籤:

1.建立一個流對象,下面哪個選項的代碼是錯誤的?(B )

A)new BufferedWriter(new FileWriter("a.txt")); B)new BufferedReader(new FileInputStream("a.dat")); C)new GZIPOutputStream(new FileOutputStream("a.zip")); D)new ObjectInputStream(new FileInputStream("a.dat"));

2.getCustomerInfo()方法如下,try中可以捕獲三種類型的異常,如果在該方法運行中產生了一個IOException,將會輸出什麼結果(A)

public void getCustomerInfo() {  try {     // do something that may cause an Exception   } catch (java.io.FileNotFoundExceptionex){     System.out.print("FileNotFoundException!");   } catch (java.io.IOExceptionex){     System.out.print("IOException!");   } catch (java.lang.Exceptionex){     System.out.print("Exception!");   }} 

A)IOException!  

B)IOException!Exception!  

C)FileNotFoundException!IOException! 

D)FileNotFoundException!IOException!Exception!

3. 下面代碼的運行結果為:(C)
import java.io.*;import java.util.*;public class foo{ public static void main (String[] args){ String s; System.out.println("s=" + s); }}

A 代碼得到編譯,並輸出“s=”

B 代碼得到編譯,並輸出“s=null”

C 由於String s沒有初始化,代碼不能編譯通過

D 代碼得到編譯,但捕獲到 NullPointException異常

4.指出下列程式啟動並執行結果 (B)

public class Example {String str = new String("good");char[] ch = { ‘a‘, ‘b‘, ‘c‘ };public static void main(String args[]) {Example ex = new Example();ex.change(ex.str, ex.ch);System.out.print(ex.str + " and ");System.out.print(ex.ch);}public void change(String str, char ch[]) {str = "test ok";ch[0] = ‘g‘;}}

A、 good and abc

B、 good and gbc

C、 test ok and abc

D、 test ok and gbc 

JAVA面試題(1)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.