2017年計算機2級Java檢測試題

學識都 人氣:3.13W

Java 編程語言是個簡單、面向對象、分佈式、解釋性、健壯、安全與系統無關、可移植、高性能、多線程和動態的語言。下面是小編收集的計算機2級Java檢測試題,希望大家認真閱讀!

2017年計算機2級Java檢測試題

單選題

1). 順序存儲結構____。

A.僅適合於靜態查找表的存儲

B.僅適合於動態查找表的存儲

C.既適合靜態又適合動態查找表的存儲

D.既不適合靜態又不適合動態查找表的存儲

正確答案:C

2). 在編寫Java application程序時,若需要使用到標準輸入輸出語句,必須在程序的開頭寫上____語句。

A.import java.awt.*;

B.import java.applet.applet;

C.import java.io.*;

D.import java.awt.Graphics;

正確答案:C

3). 關於以下程序段的.執行結果,說法正確的是public class Borley extends Thread{public static void main(String argv[]){Borley b = new Borley(); b.start(); }public void run(){System.out.println("Running");}}

A.編譯通過並執行,但無輸出

B.編譯通過並執行,輸出:Running

C.產生錯誤,沒有Thread類對象

D.產生錯誤,沒有通道到達Thread包

正確答案:B

4). 線性表若採用鏈表存儲結構時,要求內存中可用存儲單元的地址____。

A.必須是連續的

B.部分地址必須是連續的

C.一定是不連續的

D.連續不連續都可以

正確答案:D

5). 在Java中,能實現多重繼承效果的方式是____。

A.內部類

B.適配器

C.接口

D.同步

正確答案:C

6). 在編寫異常處理的Java程序中,每個catch語句塊都應該與____語句塊對應,使得用該語句塊來啓動Java的異常處理機制。

A.if-else

B.switch

C.try

D.throw

正確答案:C

簡單應用題(共24分)

本題的功能是通過按鈕來選擇窗口顯示的風格。窗口

中有三個按鈕:“Metal”、“Motif”和“Windows”,單擊任何一

個按鈕,就能將窗口的風格改變爲按鈕名稱所對應的風格。

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class PlafPanel extends JPanel implements ActionLis-

tener

{public ()

{metaIButton=new JButton("Metal");

motifButtOn=new J Button("Motif");

windowsButton=new JButton("Windows");

add(metalButton);

add(motifButton);

add(windowsButton);

metalButton.addActionListener(this);

motifButton.addActionListener(this);

windowsButton.addActionListener(this);

}

Dublic void actionPerformed(ActionEvent evt)

{Object source=evt.getSource();

String plaf="":

if(source= =metalButton)

plaf="javax.swing.plaf.metal.MetalLookAnd-

Feel";

else if(source= =motifButton)

plaf="com.sun.java.swing.plaf.motif.Moti-

fLookAndFeel";

else if(source= =windowsButton)

Dlaf="com.sun.java.swing.plaf.windows.Win-

dowsLookAndFeel";

try

{UIManager.setLookAndFeel( );

SwingUtilities.updateComponentTreeUI(this);

}

catch(Exception e){)

}

private JButton metalButton;

private JButton motifButton;

private JButton windowsButton;

}

class PlafFrame extends JFrame

{public PlafFrame()

{ setTitle("simple");

setSize(300,200);

addWindowListener(new WindowAdapter()

{public void windowClosing(WindowEvent e)

{System.exit(O);

}

});

Container contentPane=getContentPane();

contentPane.add(new PlafPanel());

}

}

public class java2

{public static void main(String[]args)

f JFrame frame=new PlafFrame();

frame.show();

}