918JAVA面试题.docx
- 文档编号:12475960
- 上传时间:2023-04-19
- 格式:DOCX
- 页数:37
- 大小:27.71KB
918JAVA面试题.docx
《918JAVA面试题.docx》由会员分享,可在线阅读,更多相关《918JAVA面试题.docx(37页珍藏版)》请在冰豆网上搜索。
918JAVA面试题
(1)
1.publicclasstest{
2.publicstaticvoidmain(Stringargs[]){
3.inti=0xFFFFFFF1;
4.intj=~i;
5.
6.}
7.}
第五行中,J的十进制数值是多少?
A.0
B.1
C.14
D.–15
E.第三行编译错误。
F.第四行编译错误。
(2)
Integeri=newInteger(42);
Long1=newLong(42);
Doubled=newDouble(42.0);
哪两个表达式的值是真?
(选择两项)
A.(i==1)
B.(i==d)
C.(d==1)
D.(i.equals(d))
E.(d.equals(i))
F.(i.equals(42))
(3)
1.publicclasstest{
2.privatestaticintj=0;
3.
4.privatestaticbooleanmethodB(intk){
5.j+=k;
6.returntrue;
6.}
7.
8.publicstaticvoidmethodA(inti){
9.booleanb:
10.b=i<10|methodB(4);
11.b=i<10||methodB(8);
12.}
13.
14.publicstaticvoidmain(Stringargs[]){
15.methodA(0);
16.system.out.printIn(j);
17.}
18.}
所得结果是什么?
A.程序打印“0”
B.程序打印“4”
C.程序打印“8”
D.程序打印“12”
E.代码没有结束.
(4)
1.publicclassFoo{
2.publicstaticvoidmain(String[]args){
3.StringBuffera=newStringBuffer(“A”);
4.StringBufferb=newStringBuffer(“B”);
5.operate(a,b);
6.system.out.printIn{a+“,”+b};
7.}
8.staticvoidoperate(StringBufferx,StringBuffery){
9.x.append{y};
10.y=x;
11.}
12.}
结果是什么?
A.代码编译并输出“A,B”.
B.代码编译并输出“A,A”.
C.代码编译并输出“B,B”.
D.代码编译并输出“AB,B”.
E.代码编译并输出“AB,AB”.
F.代码不能编译.
(5)
1.Publicclasstest{
2.PublicstaticvoidstringReplace(Stringtext){
3.Text=text.replace(‘j’,‘i’);
4.}
5.
6.publicstaticvoidbufferReplace(StringBuffertext){
7.text=text.append(“C”);
8.}
9.
10.publicstaticvoidmain(Stringargs[]){
11.StringtextString=newString(“java”);
12.StringBuffertextBufferString=newStringBuffer(“java”);
13.
14.stringReplace(textString);
15.BufferReplace(textBuffer);
16.
17.System.out.printIn(textString+textBuffer);
18.}
19.}
输出结果是什么?
(6)
1.publicclasstest{
2.publicstaticvoidadd3(Integeri){
3.intval=i.intValue();
4.val+=3;
5.i=newInteger(val);
6.}
7.
8.publicstaticvoidmain(Stringargs[]){
9.Integeri=newInteger(0);
10.add3(i);
11.system.out.printIn(i.intValue());
12.}
13.}
结果是什么?
A.编译失败.
B.打印“0”.
C.打印“3”.
D.编译通过但是运行时第3行抛出异常.
(7)
1.publicclassConstOver{
2.publicConstOver(intx,inty,intz){
3.}
4.}
哪两个语句重载了ConstOver这个类的构造器?
(选择两项)
A.ConstOver(){}
B.ProtectedintConstOver(){}
C.PrivateConstOver(intz,inty,bytex){}
D.PublicObjectConstOver(intx,inty,intz){}
E.PublicvoidConstOver(bytex,bytey,bytez){}
(8)
1.publicclassMethodOver{
2.publicvoidsetVar(inta,intb,floatc){
3.}
4.}
以下哪两个重载了setVar方法?
(选择两项)
A.PrivatevoidsetVar(inta,floatc,intb){}
B.ProtectedvoidsetVar(inta,intb,floatc){}
C.PublicintsetVar(inta,floatc,intb){returna;}
D.PublicintsetVar(inta,intb,floatc){returna;}
E.ProtectedfloatsetVar(inta,intb,floatc){returnc;}
(9)
1.classBaseClass{
2.Privatefloatx=1.0f;
3.protectedfloatgetVar(){returnx;}
4.}
5.classSubclassextendsBaseClass{
6.privatefloatx=2.0f;
7.//insertcodehere
8.}
哪两个是重写方法getVar的正确写法?
(选择两项)
A.FloatgetVar(){returnx;}
B.PublicfloatgetVar(){returnx;}
C.FloatdoublegetVar(){returnx;}
D.PublicfloatgetVar(){returnx;}
E.PublicfloatgetVar(floatf){returnf;}
(10)
以下哪两个选项表现了“isa”的关联?
(选择两项)
A.publicinterfacePerson{}
publicclassEmployeeextendsPerson{}
B.publicinterfaceShape{}
publicclassEmployeeextendsShape{}
C.publicinterfaceColor{}
publicclassEmployeeextendsColor{}
D.publicclassSpecies{}
publicclassAnimal{privateSpeciesspecies;}
E.interfaceComponent{}
ClassContainerimplementsComponent{
PrivateComponent[]children;
}
(11)
以下哪个语句是对的?
A.匿名内部类可以声明为final.
B.匿名内部类可以声明为private.
C.匿名内部类可以实现多个接口
D.匿名内部类可以访问所有作用域的final变量
(12)
1.packagefoo;
2.
3.publicclassOuter{
4.publicstaticclassInner{
5.}
6.}
以下哪个语句是对的?
A.Innerclass可以用“newOuter.Inner()”实例化
B.Innerclass不能在foo包外实例化.
C.Innerclass只能在outerclass里实例化.
D.在bar包里Innerclass可以用“newinner()”实例化
(13)
1.publicclassenclosingone{
2.publicclassinsideone{}
3.}
4.publicclassinertest{
5.publicstaticvoidmain(string[]args){
6.enclosingoneeo=newenclosingone();
7.//insertcodehere
8.}
9.}
在第7行,以下哪个语句正确构造了内部类的实例?
A.InsideOnewei=eo.newInsideOn();
B.Eo.InsideOneei=eo.newInsideOne();
C.InsideOneei=EnclosingOne.newInsideOne();
D.EnclosingOne.InsideOneei=eo.newInsideOne();
(14)
1.interfacefoo{
2.intk=0;
3.}
4.
5.publicclasstestimplementsFoo{
6.publicstaticvoidmain(Stringargs[]){
7.inti;
8.Testtest=newtest();
9.i=test.k;
10.i=Test.k;
11.i=Foo.k;
12.}
13.}
14.
结果是什么?
A.编译通过.
B.第2行编译不通过.
C.第9行编译不通过.
D.第10行编译不通过.
E.第11行编译不通过.
(15)
1.//pointX
2.publicclassfoo{
3.publicstaticvoidmain(String[]args)throwsException{
4.printWriterout=newPrintWriter(new
5.java.io.outputStreamWriter(System.out),true;
6.out.printIn(“Hello”);
7.}
8.}
以下哪句语句能顺利编译运行代码?
A.Importjava.io.PrintWriter;
B.Includejava.io.PrintWriter;
C.Importjava.io.OutputStreamWriter;
D.Includejava.io.OutputStreamWriter;
E.Nostatementisneeded.
(16)
哪两个选项是JAVA的关键字?
(选择两项)
A.Run
B.Import
C.Default
D.Implement
(17)
哪三个是关于浮点型的正确声明?
A.Floatfoo=-1;
B.Floatfoo=1.0;
C.Floatfoo=42e1;
D.Floatfoo=2.02f;
E.Floatfoo=3.03d;
F.Floatfoo=0x0123;
(18)
1.intindex=1;
2.boolean[]test=newBoolean[3];
3.booleanfoo=test[index];
结果是什么?
A.Foohasthevalueof0.
B.Foohasthevalueofnull.
C.Foohasthevalueoftrue.
D.Foohasthevalueoffalse.
E.Anexceptionisthrown.
F.Thecodewillnotcompile.
(19)
1.publicclasstest{
2.publicstaticvoidmain(string[]args)(
3.stringfoo=args[1];
4.stringfoo=args[2];
5.stringfoo=args[3];
6.)
7.}
在命令行调用:
JavaTestredgreenblue
结果是什么?
A.Bazhasthevalueof“”
B.Bazhasthevalueofnull
C.Bazhasthevalueof“red”
D.Bazhasthevalueof“blue”
E.Baxhasthevalueof“green”
F.Thecodedoesnotcompile.
G.Theprogramthrowsanexception.
(20)
8.intindex=1;
9.int[]foo=newint[3];
10.intbar=foo[index];
11.intbaz=bar+index;
结果是什么?
A.Baz=0
B.Baz=1
C.Baz=2
D.会抛出异常.
E.不能正常编译
(21)
Given:
1.publicclassfoo{
2.publicstaticvoidmain(String[]args){
3.Strings;
4.system.out.printIn(“s=”+s);
5.}
6.}
结果是什么?
A.Thecodecompilesand“s=”isprinted.
B.Thecodecompilesand“s=null”isprinted.
C.Thecodedoesnotcompilebecausestringsisnotinitialized.
D.Thecodedoesnotcompilebecausestringscannotbereferenced.
E.Thecodecompiles,butaNullPointerExceptionisthrownwhentoStringiscalled.
(22)
以下哪个选项能声明一种方法,使其能在一个子类中得以运行?
A.Publicdoublemethoda();
B.Staticvoidmethoda(doubled1){}
C.Publicnativedoublemethoda();
D.Abstractpublicvoidmethoda();
E.Protectedvoidmethoda(doubled1){}
(23)
Youwantsubclassesinanypackagetohaveaccesstomembersofasuperclass.Whichisthemost
restrictiveaccessmodifierthatwillaccomplishthisobjective?
A.Public
B.Private
C.Protected
D.Transient
E.Noaccessmodifierisqualified
(24)
1.abstractclassabstrctIt{
2.abstractfloatgetFloat();
3.}
4.publicclassAbstractTestextendsAbstractIt{
5.privatefloatf1=1.0f;
6.privatefloatgetFloat(){returnf1;}
7.}
结果是什么?
A.编译成功.
B.第6行编译错误.
C.第6行编译错误.
D.第2行编译错误..
(25)
1.publicclasstest(
2.publicintaMethod()[
3.staticinti=0;
4.i++;
5.returnI;
6.]
7.publicstaticvoidmain(Stringargs[]){
8.testtest=newtest();
9.test.aMethod();
10.intj=test.aMethod();
11.System.out.printIn(j);
12.}
13.)
结果是什么?
A.Compilationwillfail.
B.Compilationwillsucceedandtheprogramwillprint“0”
C.Compilationwillsucceedandtheprogramwillprint“1”
D.Compilationwillsucceedandtheprogramwillprint“2”
(26)
Given:
1.classsuper{
2.publicfloatgetNum(){return3.0f;}
3.}
4.
5.publicclassSubextendsSuper{
6.
7.}
哪个方法放在第6行会导致编译出错?
A.PublicfloatgetNum(){return4.0f;}
B.PublicvoidgetNum(){}
C.PublicvoidgetNum(doubled){}
D.PublicdoublegetNum(floatd){retrun4.0f;}
(27)
哪个声明阻止了在外部创建实例?
A.StaticclassFooBar{}
B.PrivateclassFooBar{}
C.AbstractpublicclassFooBar{}
D.FinalpublicclassFooBar{}
E.FinalabstractclassFooBar{}
(28)
1.byte[]arry1,array2[];
2.bytearray3[][];
3.byte[][]array4;
如果每个数组已经初始化,那么以下哪个声明会出现编译错误?
A.Array2=array1;
B.Array2=array3;
C.Array2=array4;
D.BothAandB
E.BothAandC
F.BothBandC
(29)
1.classsuper(
2.publicintI=0;
3.
4.publicsuper(stringtext)(
5.I=1
6.)
7.)
8.
9.publicclasssubextendssuper(
10.publicsub(stringtext)(
11.i=2
12.)
13.
14.publicstaticvoidmain(straingargs[])(
15.subsub=newsub(“Hello”);
16.system.out.PrintIn(sub.i);
17.)
18.)
结果是什么?
A.编译失败.
B.程序输出“0”
C.程序输出“1”
D.程序输出“2”
(30)
Given:
1.publicclassreturnIt(
2.returnTypemethodA(bytex,doubley)(
3.return(short)x/y*2;
4.)
5.)
哪个是第二行中methodA的正确返回类型?
A.Int
B.Byte
C.Long
D.Short
E.Float
F.Double
(31)
给定ActionEvent,哪个方法能够识别受影响的组件?
A.GetClass.
B.GetTarget.
C.GetSource.
D.GetComponent.
E.GetTargetComponent.
(32)
哪个是MouseMotionListener接口的构造方法?
A.PublicvoidmouseMoved(MouseEvent)
B.PublicbooleanmouseMoved(MouseEvent)
C.PublicvoidmouseMoved(MouseMotionEvent)
D.PublicbooleanMouseMoved(MouseMotionEvent)
E.PublicbooleanmouseMoved(MouseMotionEvent)
(33)
1.importjava.awt*;
2.
3.publicclassXextendsFrame(
4.publicstaticvoidmain(st
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 918 JAVA 试题
![提示](https://static.bdocx.com/images/bang_tan.gif)