jAVA程序设计考前准备.docx
- 文档编号:9492075
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:49
- 大小:37.17KB
jAVA程序设计考前准备.docx
《jAVA程序设计考前准备.docx》由会员分享,可在线阅读,更多相关《jAVA程序设计考前准备.docx(49页珍藏版)》请在冰豆网上搜索。
jAVA程序设计考前准备
1.Whichofthefollowingisaconstant,accordingtoJavanamingconventions?
A.MAX_VALUE
B.Test
C.read
D.ReadInt
2.Youshouldoverridethe__________methodtodrawthingsonaSwingcomponent.
A.repaint()B.update()
C.paintComponent()D.init()
3.Whichclasscantheuserdefinedexceptionclassinheritfrom?
A.Error
B.AWTError
C.VirtualMachineError
D.Exceptionanditssubclass
4.WhichiswrongabouttheFrameclass?
A.FrameisthedirectsubclassoftheWindowclass
B.theobjectofFramedisplaysawindow
C.Frameisvisiblebydefault
D.thedefaultlayoutofFrameisBorderLayout
1.ThedefaultlayoutofthecontentPaneofaframeis__________.
A、FlowLayoutB、GridLayout
C、BorderLayoutD、None
2.Whatisdisplayedontheconsolewhenthefollowingprogramisrun?
publicclassTest5{
publicstaticvoidmain(Stringargs[]){
Strings1=newString("hello");
Strings2=newString("hello");
System.out.print(s1==s2);
System.out.print(",");
System.out.println(s1.equals(s2));
}
}
A、true,falseB、true,trueC、false,trueD、false,false
3.WhichmethodcanyouusetofindoutthenumberofthebytesinafileusingInputStream?
A、length()B、available()
C、size()D、getSize()
4.Whatisthereturntypeofthemain()method?
A、publicB、staticC、voidD、main
5.Youshouldoverridethe__________methodtodrawthingsonaSwingcomponent.
A、repaint()B、update()
C、paintComponent()D、init()
6.Whichclasscantheuserdefinedexceptionclassinheritfrom?
A、Error
B、AWTError
C、VirtualMachineError
D、Exceptionanditssubclass
7.WhichmethodisDeprecatedwhenwritingthemultithreadprogram?
A、wait()B、notify()C、stop()D、notifyall()
8.The__________methodisexecutedwhenthepagebecomesinactive.
A、destroy()B、init()C、start()D、stop()
9.Whatistheextensionofthebytecodefile?
A、javaB、classC、htmlD、exe
10.Whichlineiswrongwhenthefollowingcodefragmentiscompiling?
①publicvoidmodify(){
②inti,j,k;
③i=100;
④while(i>0){
⑤j=i*2;
⑥System.out.println("Thevalueofjis"+j);
⑦k=k+1;
⑧}
⑨}
A、line4B、line6C、line7D、line8
11.Swingcomponentsthatdon’trelyonnativeGUIarereferredtoas___________.
A、lightweightcomponents
B、heavyweightcomponents
C、GUIcomponents
D、Non-GUIcomponents
12.Whichofthefollowingclassesisaheavyweightcomponent?
A、JButtonB、JTextFieldC、JPanelD、JFrame
13.Whichmethodisusedtoclosethestream?
A、skip()B、close()C、mark()D、reset()
14.Whichmethodisusedtoexecutethethread?
A、run()B、start()C、sleep()D、suspend()
15.WhichiswrongabouttheFrameclass?
A、FrameisthedirectsubclassoftheWindowclass
B、theobjectofFramedisplaysawindow
C、Frameisvisiblebydefault
D、thedefaultlayoutofFrameisBorderLayout
16.WhichmethodisusedtoclosethebrowserandreleaseallresourcestheAppletused?
A、init()B、start()C、paint()D、destroy()
17.WhichiswrongamongthefollowingJAVAcodefragment?
A、packagetestpackage;B、importjava.io.*;
publicclassTest{}packagetestpackage;
publicclassTest{}
C、importjava.io.*;D、importjava.io.*;
classPerson{}importjava.awt.*;
publicclassTest{}publicclassTest{}
18.TobealistenerforActionEvent,anobjectmustbeaninstanceof____________.
A、ActionEventB、ActionListenerC、EventObjectD.WindowListener
19._________describesthestateofanobject.
A、attributes
B、methods
C、constructors
D、nooftheabove
20.Whichinterfaceisusedtohandlingobjecttransmission?
A、Serializable B、Cloneable C、ItemListener D、ActionListener
1.C2.C3.B4.C5.C6.D7.C8.C9.B10.C
11.A12.D13.B14.A15.C16.D17.B18.B19.A20.A
1.创建两个线程,每一个都打印1到10之间的素数。
publicclassMyThreadextendsThread
{
publicMyThread(Stringname)
{super(name);}
publicvoidrun()
{//并发执行的程序代码
inti,j;
for(i=1;i<10;i++)
{for(j=2;j
if(i%j==0)break;
if(j==i)System.out.println(""+i+""+getName());//输出当前数字及线程名
try{sleep(1000);//休眠1秒,给其它线程运行的机会
}catch(InterruptedExceptione){}
}
}
publicstaticvoidmain(String[]args)
{//创建线程1的对象及线程2的对象
MyThreadmyThread1=newMyThread("线程1");
MyThreadmyThread2=newMyThread("线程2");
//启动两个线程
myThread1.start();
myThread2.start();
}
}
2.设计一SwingGUI程序,每次单击按钮时,标签中的记数就自动加1。
界面可参考下图。
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
publicclassT1extendsJFrameimplementsActionListener
{
privateJButtonjb=newJButton("请点击这里");
privateJLabeljl=newJLabel("你总共点击了0次");
privateintcount=0;
T1()
{
super("程序设计");
this.setSize(300,200);
this.getContentPane().setLayout(null);
jb.setBounds(20,20,100,40);
jl.setBounds(20,100,100,40);
add(jb);
add(jl);
jb.addActionListener(this);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
publicvoidactionPerformed(ActionEvente)
{
Count++;
jl.setText("你总共点击了"+count+"次");
}
publicstaticvoidmain(Stringarg[])
{
newT1();
}
}
1.下列语句序列执行后,k的值是(B)。
intm=3,n=6,k=0;
while((m++)<(--n))++k;
A)0B)1C)2D)3
2.设i、j为int型变量名,a为int型数组名,以下选项中,正确的赋值语句是(B)。
A)i=i+2B)a[0]=7;
C)i++---j;D)a(0)=66;
3.Java语言的类间的继承关系是(B)。
A)多重的B)单重的C)线程的D)不能继承
4.设有定义inti=6;,则执行以下语句后,i的值为(C)。
i+=i-1;
A)10B)121C)11D)100
5.下列选项中,用于在定义子类时声明父类名的关键字是(C)。
A)interfaceB)packageC)extendsD)class
6.若已定义byte[]x={11,22,33,-66};
其中0≤k≤3,则对x数组元素错误的引用是(C)。
A)x[5-3]B)x[k]C)x[k+5]D)x[0]
7.下列语句序列执行后,ch1的值是(B)。
charch1='A',ch2='W';
if(ch1+2 A)'A'B)'B'C)'C'D)B 8.下列语句序列执行后,i的值是(D)。 inti=8,j=16; if(i-1>j)i--;elsej--; A)15B)16C)7D)8 9.下列语句序列执行后,k的值是(C)。 inti=10,j=18,k=30; switch(j-i) {case8: k++; case9: k+=2; case10: k+=3; default: k/=j; } A)31B)32C)2D)33 10.下面语句执行后,i的值是(B)。 for(inti=0,j=1;j<5;j+=3)i=i+j; A)4B)5C)6D)7 11.设有定义floatx=3.5f,y=4.6f,z=5.7f;则以下的表达式中,值为true的是(B)。 A)x>y||x>zB)x! =y C)z>(y+x)D)x (x 12.下列语句序列执行后,i的值是(D)。 inti=16; do{i/=2;}while(i>3); A)16B)8C)4D)2 13.以下由for语句构成的循环执行的次数是(B)。 for(inti=0;true;i++); A)有语法错,不能执行B)无限次 C)执行1次D)一次也不执行 14.定义类头时能使用的修饰符是(C)。 A)privateB)staticC)abstractD)protected 15.设int型变量a、b,float型变量x、y,char型变量ch均已正确定义并赋值, 正确的switch语句是D)。 A)switch(x+y)B)switch(ch+1) {......}{......} C)switchchD)switch(a+b); {......}{......} 16.下列最终属性i的定义中,正确的是()。 A)staticfinalinti=100;B)finalinti=1.2; C)finali='w';D)finalchari; 17.下列类定义中,不正确的是(C)。 A)classx{....} B)classxextendsy{....} C)staticclassximplementsy1,y2{....} D)publicclassxextendsApplet{....} 18.设x、y为已定义的类名,下列声明x类的对象x1的语句中正确的是()。 A)staticxx1;B)publicxx1=newx(int123); C)yx1;D)xx1=x(); 19.设i、j、k为类x中定义的int型变量名,下列类x的构造函数中不正确的是(B)。 A)x(intm){...}B)voidx(intm){...} C)x(intm,intn){...}D)x(inth,intm,intn){...} 20.下列方法定义中,正确的是(A)。 A)intx(){charch='a';return(int)ch;} B)voidx(){...returntrue;} C)intx(){...returntrue;} D)intx(inta,b){returna+b;} 21.用于定义类成员的访问控制权的一组关键字是(D)。 A)class,float,double,public B)float,boolean,int,long C)char,extends,float,double D)public,private,protected 22.不能构成循环的语句是(C)。 A)for语句B)while语句C)switch语句D)do__while语句 23.下列程序段执行后b3的结果是(D)。 booleanb1=true,b2,b3; 24=b1? b1: b2; A)0B)1C)trueD)false 25下面数据结构中,属于非线性的是(B)。 A)线性表B)树C)队列D)堆栈 11.设有定义inti=123;longj=456;下面赋值不正确的语句是(D)。 A)j=i;B)j=(long)i;C)i=(int)j;D)i=j; 1、关于Java语言叙述错误的是: (C) A.Java语言具有跨平台性 B.Java是一种面向对象的语言 C.Java语言中的类可以多继承 D.Java的垃圾收集机制自动回收程序已不再使用的对象 2、以下叙述正确的是: (B)的确台a A.构造方法必须是public方法 B.main方法必须是public方法 C.Java应用程序的文件名可以是任意的 D.构造方法应该声明为void类型 3、关于Java中数据类型叙述正确的是: (B) A、整型数据在不同平台下长度不同 B.boolean类型数据只有2个值,true和false C.数组属于简单数据类型 D.Java中的指针类型和C语言的一样 4、设intx=1,floaty=2,则表达式x/y的值是: (D) A.0 B.1 C.2 D.以上都不是 5、以下语句有语法错的是: (A) A.intx=1;y=2;z=3 B.for(intx=10,y=0;x>0;x++); C.while(x>5); D.for(;;); 6、关于类和对象的叙述正确的是: (A) A.Java的类分为两大部分: 系统定义的类和用户自定义的类 B.类的静态属性和全局变量的概念完全一样,只是表达形式不同 C.类的成员至少有一个属性和一个方法 D.类是对象的实例化 7、以下有关构造方法的说法,正确的是: (A) A.一个类的构造方法可以有多个 B.构造方法在类定义时被调用 C.构造方法只能由对象中的其它方法调用 D.构造方法可以和类同名,也可以和类名不同 8、以下有关类的继承的叙述中,正确的是: (D) A.子类能直接继承父类所有的非私有属性,也可通过接口继承父类的私有属性 B.子类只能继承父类的方法,不能继承父类的属性 C.子类只能继承父类的非私有属性,不能继承父类的方法 D.子类不能继承父类的私有属性 9、下列属于容器的组件有: (B) A.JButton B.JPane C.Canvas D.JTextArea 10、void的含义: (C) A.方法体为空 B.定义的方法没有形参 C.定义的方法没有返回值 D.方法的返回值不能参加算术运算 11、关于Java中异常的叙述正确的是: (D) A.异常是程序编写过程中代码的语法错误 B.异常是程序编写过程中代码的逻辑错误 C.异常出现后程序的运行马上中止 D.异常是可以捕获和处理的 12、所有的异常类皆继承哪一个类? (C) A.java.io.Exception B.java.lang.Throwable C.java.lang.Exception D.java.lang.Error 13、下面哪个不是java语言中的关键字? (B) A.long B.sizeof C.instanceof D.const 14、为实现进程之间的通信,需要使用下列那种流才合适? (D) A.Datastream B.Filestream C.Bufferedstream D.Pipedstream 15、在复选框中移动鼠标,然后单击一选项,要捕获所选项必需实现哪个接口? (D) A.ActionListener B.MouseListener C.MouseMotionListern D.ItemListener 1.下面哪些是short型的取值范围[C] A.-27–27-1 B.0–216-1 C.-215–215-1 D.-231–231-1 2.下面哪些是合法的标识符[ABE] A.$persons B.TwoUsers C.*point D.this E._endline 3.哪些是将一个十六进制值赋值给一个long型变量[D] A.longnumber=345L; B.longnumber=0345; C.longnumber=0345L; D.longnumber=0x345L; 4.下面的哪些程序片断可能导致错误。 [BD] A. Strings="Gonewiththewind"; Stringt="good"; Stringk=s+t;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- jAVA 程序设计 考前 准备