2016年Java考試精選程序閱讀題

  1.寫出以下程序的運行結果。

2016年Java考試精選程序閱讀題

class First {

First(  ) {

tln ("in First"); } }

public class Second extends First { Second(  ) {

tln("in Second"); } public static void main(String[] args) { Second mine= new Second(  ); } }

程序運行的結果:

in First in Second

  2.解釋程序中語句的'含義

文本文件中的內容是 abcd

下面的程序將文件中的內容寫到文件中和屏幕上 import .*;

public class filecopy {

public static void main(String[] args) { try {

StringBuffer str=new StringBuffer(  );

FileInputStream fin=new FileInputStream("");

意義

FileOutputStream fout=new FileOutputStream("");

意義

int c;

while((c=(  ))!=-1) {

e(c); 意義

nd((char)c); 意義

}

e(  ); e(  );

String str2=ring(  );

tln(str2); 顯示的結果是

}catch(Exception c) {

tln(c); } } }

實例化輸入流對象,指定輸入流來源文件爲 實例化輸出流對象,指定輸出流目標文件爲 將C寫入到輸出流對象中

將整數C轉化爲字符,並添加到字符串str的尾部 abcd