




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
2022年計算機二級考試JAVA預測練習試題
21.若定義inta=2,b一2,以下表達式中值不為4的是()。
A.a*(++b)
B.a*(b++)
C.a+b
D.a*b
22.以下可以獲得構件前風光的方法是()。
A.getsize()
B.getForeground()
C.getBackground()
D.paint()
23.以下程序的運行結果是()。
publicclasstest{
privateString[]data={¨10“,“10.5“);
publicvoidfun(){
doubles=0:
for(inti=0;i<3;j++){
try{
s=s+Integer.parseInt(data[i]);
catch(Exceptione){
System.out.print(“errorl:“+data[i]);
}
}
}
publicstaticvoidmain(string[]args){
try{
testd=newtest():
d.fun():
}catch(Exceptione){
System.OUt.println(“error2“)
}
}
}
A.errorl:10.5B.error2
C.errorl:10.5error2D.以上都不對
24.以下程序片段中,能通過編譯的是()。
A.publicabstractclassAnimal{
publicvoidspeak();}
B.publicabstractclassAnimal{
publicvoldspeak()();}
C.publicclassAnimal{
pubilcabstractvoidspeak();}
D.publicabstractclassAnimal{
pubilcabstractvoidspeak()();}
25.以下不屬于接口WindowListener的方法是()。
A.windowClosing()
B.windowClosed()
C.windowMinimized()
D.windowOpened()
26.以下選項中,不能輸出100個整數的是()。
A.for(inti=0;i<100;i++)
System.out.println(i);
B.inti=0;
do{
System.out.println(i);
i++:
}while(i<100);
C.inti=0:
while(i<100){
System.out.println(i);
i++:
}
D.inti=0:
while(i<100){
i++:
if(i<100)continue:
System.out.println(i);
}
27.類變量必需帶有的修飾符是()。
A.static
B.final
C.public
D.volatile
28.以下選項中屬于字符串常量的是()。
A.·abc·
B.“abe“
C.[abc]
D.(abc)
29.Java程序默認引用的包是()。
A.java.text包B.java.awt包
C.java.lang包D.java.util包
30.為使以下代碼正常運行,應當在下畫線處填入的選項是()。
ObjectInputStreamIn=
new(newFilelnputStream(“employee.
doc“));
Employee[]newstaff=(Employee[])in.readObject
();
In.close();
A.Reader
B.InputStream
C.Objectlnput
D.ObjectlnputStream
31.以下代碼將對象寫入的設備是()。
ByteArrayOutputStreambout=newByteArrayOut-
putStream();
ObjectOutputStreamout=newObjectOutputStream
(bout);
out.writeObject(this);
out.close();
A.內存
B.硬盤
C.屏幕
D.網絡
32.為使以下代碼正常運行,應當在下畫線處填入的選項是()。
int[]numbers=newint[n];
for(inti=0;inumbers[i]=i+1:
A.sizeB.length
C.dimensionD.measurement
33.為使以下代碼正常運行,應當在下畫線處填入的選項是()。
abstractclassperson{
publicPerson(Stringn){
name=n:
}
publicStringgetDescription();
publicStringgetName(){
returnname;
}
privatestringname;
}
A.static
B.private
C.abstract
D.final
34.以下能夠正確創立線程的方法是(.)。
Ⅰ.繼承java.lang.Thread類,并重寫run()方法
Ⅱ.繼承java.lang.Runnable類,并重寫start()方法
Ⅲ.實現java.1ang.Thread接口,并實現run()方法
IV.實現java.lang.Runable接口,并實現run()方法
A.Ⅰ,ⅢB.Ⅱ,IV
C.Ⅱ,ⅢD.I,IV
35.以下線程狀態轉換序列,在線程實際運行中可能消失的序列是()。
A.新建→運行→堵塞→終止
B.……運行→堵塞→可運行→終止
C.……可運行→運行→堵塞→運行……
D.新建→可運行→運行→堵塞→可運行……
36.為了支持壓棧線程與彈棧線程之間的交互與同步,應
在下畫線處填入的選項是()。
publicclassStackTest{
privateintidx=0;
privateint[]data=newint[8]
publicvoidpush(inti){
synchronized(this){
;
data(idx)=i:
idx++:
}
}
}……
A.this.notify()
B.interrupt()
C.this.wait()
D.sleep()
37.對以下程序的表達中,正確的選項是()。
1)publicclassXextendsThreadimplementsRunnable{
2)publicvoidrun(){
3)system.out.println(“thisisrun()“);
4)}
5)publicstaticvoidmain(Stringargs[]){
6)Threadt=newThread(newX());
7)t.start();
8)}
9)}
A.第l行會產生編譯錯誤
B.第6行會產生編譯錯誤
C.第6行會產生運行錯誤
D.程序正常運行
38.以下關于Applet的表達中,正確的選項是()。
A.Applet不僅可以嵌入到掃瞄器中運行,還可以獨立運行
B.Applet的主類要定義為Applet類或JApplet類的子類
C.同一個頁面中的Applet之間不能通信
D.Applet不支持多線程
39.當一個Applet所在的Web頁面被其他頁面掩蓋后,不行能被調用的Applet方法是()。
A.destroy()
B.init()
C.stop()
D.start()
二、根本操作題(共18分)
此題分別比擬兩個字符串“A“和“a“是否相等,并比擬兩個字符“A“和“a“是否相等,并輸出比擬結果。
publicclassjaval{
publicstaticvoidmain(String[]args){
;
cl=’A’;c2=’a’;
Stringstrl=newString(“A“),str2=newString
(“a“):
if()
System.Out.println(“char“+c1+“equals“+“char“
+c2);
else
System.OUt.println(“char“+cl+“doesn’tequal
“+“char“+c2);
if()
System.out.println(“string“+strl+“equals“+
“string“+str2):
else
System.OUt.println(“string“+strl+“doesn’te-
qual“+“string“+str2);.
}
}
三、簡潔應用題(共24分)
此題是一個Applet,頁面上有一個按鈕“請單擊”,單擊該按鈕后彈出一個對話框,對話框上有三個按鈕“橙色”、“藍色”和“紅色”,單擊其中任意一個按鈕,則可以將對話框的背風光設置為按鈕名稱所對應的顏色。
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
publicclassjava2extendsJApplet
{
privateJFrameframet;
()
{
frame=newJFrame();
frame.setTitle(“java2“);
frame.setSize(300,200);
frame.getContentPane().add(newButtonPanel
());
JButtonPopButton=newJButton(“請單擊“);
getContentPane().add(PopButton);
PopButtomaddActionListener(newActionListener();
{
publicvoidactionPerformed(ActionEventevt)
{
if(frame.isVisible())frame.setVisible(false);
else;
}
});
}
}
classButtonPanelextendsJPanel
{
privateclassColorActionimplementsActionLis-
tener
{
privateColorbackgroundColor;
publicvoidactionPerformed(ActionEventaction-
event)
{
setBackground(backgroundColor);
repaint();
}
publicColorAction(Colorcolor)
{
backgroundColor=color;
}
}
publicButtonPanel()
{
JButtonjbutton=newJButton(“橙色“);
JButtonjbuttonl=newJButton(“藍色“);
JButtonjbutton2=newJButton(“紅色“);
add(jbutton);
add(jbuttonl);
add(jbutton2);
ColorActioncoloraction=newColorAction(Color.orange);
ColorActioncoloractionl=newColorAction(Color.blue);
ColorActioncoloraetion2=newColorAction(Color.red);
ibutton.addActionListener(coloraction);
ibuttonl.addActionListener(coloractionl);
jbutton2.addActionListener(coloraction2);
}
}
四、綜合應用題(共18分)
此題的功能是用按鈕來掌握文本框中文本的顏色。窗口中有兩個帶有文字標題的面板“Sampletext”和“Textcolorcontrol”,窗口的底部還有一個復選按鈕“Disablechanges”。在“Sampletext”面板中有一個帶有字符串的文本框,而在“Textcolorcontrol”面板中有三個按鈕:“Black”、“Red”和“Green”,并且每個按鈕上都有一個對應顏色的圓。單擊任意按鈕,文本框中的文本變成對應的顏色,假如選中“Disablechanges”復選項,則三個顏色按鈕變為不行用,假如取消選中復選項,則三個按鈕變為可用。
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
publicclassjava3extendsJFrame{
privateJPanelupper,middle,lower;
privateJTextFieldtext;
privateJButtonblack,red,green;
privateJCheckBoxdisable;
publicjava3(StringtitleText){
super(titleText);
addWindowListener(newWindowAdapter(){
publicvoid
windowClosing(WindowEvente){
System.exit(0);
}
}
);
upper=newJPanel();
upper.setBorder(BorderFactory.ereateTitledBor-
der(“Sampletext“));
upper.setlayout(newBorderLayout());
text=newJTextField(“Changethecolorofthis
text“):
upper.add(text,BorderLayout.CENTER);
middle=newJPanel();
middle.setBorder(BorderFactory.createTitledBor-
der(“Textcolorcontrol“));
middle.setLayout(newFlowLayout(FlowLayout.
CENTER)):
black=newJButton(“Black“,newColorIcon
(Color.black));
black.addActionListener(newButtonListener
(Color.black));
middle.add(black);
red=newJButton(“Red“,newColorIcon(Col-
or.red));
red.addActionListener(newButtonListener(Col-
or.red));
middle.add(red);
green=newJButton(“Green“,newColorIcon
(Color.green));
green.addActionListener(newButtonListener
(Color.green));
middle.add(green);
lower=newJPanel();
lower.setLayout(newFlowLayout(FlowLayout.
RIGHT));
disable=newJCheckBox(“Disablechanges“):
disable.addItemListener(newItemListener()(
publicvoiditemStateChanged(ItemEvente){
booleanenabled
=(e.getStateChange()
==ItemEvent.DESELECTED):
black.setEnabled(enabled);
red.setEnabled(enabled);
green.setEnabled(enabled);
}
}
);
lower.add(disable);
Containercp=getContentPane();
cp.add(upp
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024江西航空職業技術學院招聘筆試真題及參考答案詳解
- 電工與電子技術基礎(第三版)課件:半導體器件
- 幼兒園評價分級管理制度
- 幼兒園食堂設備管理制度
- 廣告設計公司行政管理制度
- 開發公司工程招標管理制度
- 影視公司學習及管理制度
- 微生物實驗室安全管理制度
- 護理病歷電子化管理制度
- 擔保公司法務部管理制度
- 替普瑞酮聯合硫糖鋁治療慢性非萎縮性胃炎伴糜爛的療效及安全性分析
- 《霸王茶姬》認證考核試題附答案
- 集裝箱冷板式液冷數據中心技術規范
- GB/T 7106-2019建筑外門窗氣密、水密、抗風壓性能檢測方法
- GB/T 28046.4-2011道路車輛電氣及電子設備的環境條件和試驗第4部分:氣候負荷
- (精心整理)考試作文格紙
- 倉庫管理員培訓教材課件
- (新版)供電可靠性理論考試題庫大全-上(單選、多選題)
- AS9100D體系標準中文版
- 《中國腦卒中護理指導規范(2021年版)》課件
- 學前教育學備課課件(共54張PPT)
評論
0/150
提交評論