918JAVA面试题文档格式.docx
《918JAVA面试题文档格式.docx》由会员分享,可在线阅读,更多相关《918JAVA面试题文档格式.docx(37页珍藏版)》请在冰点文库上搜索。
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};
8.staticvoidoperate(StringBufferx,StringBuffery){
9.x.append{y};
10.y=x;
11.}
结果是什么?
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.}
6.publicstaticvoidbufferReplace(StringBuffertext){
7.text=text.append(“C”);
8.}
9.
10.publicstaticvoidmain(Stringargs[]){
11.StringtextString=newString(“java”);
12.StringBuffertextBufferString=newStringBuffer(“java”);
14.stringReplace(textString);
15.BufferReplace(textBuffer);
16.
17.System.out.printIn(textString+textBuffer);
19.}
输出结果是什么?
(6)
2.publicstaticvoidadd3(Integeri){
3.intval=i.intValue();
4.val+=3;
5.i=newInteger(val);
8.publicstaticvoidmain(Stringargs[]){
9.Integeri=newInteger(0);
10.add3(i);
11.system.out.printIn(i.intValue());
13.}
A.编译失败.
B.打印“0”.
C.打印“3”.
D.编译通过但是运行时第3行抛出异常.
(7)
1.publicclassConstOver{
2.publicConstOver(intx,inty,intz){
3.}
哪两个语句重载了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){
以下哪两个重载了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;
5.classSubclassextendsBaseClass{
6.privatefloatx=2.0f;
7.//insertcodehere
哪两个是重写方法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.}
A.Innerclass可以用“newOuter.Inner()”实例化
B.Innerclass不能在foo包外实例化.
C.Innerclass只能在outerclass里实例化.
D.在bar包里Innerclass可以用“newinner()”实例化
(13)
1.publicclassenclosingone{
2.publicclassinsideone{}
4.publicclassinertest{
5.publicstaticvoidmain(string[]args){
6.enclosingoneeo=newenclosingone();
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;
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”);
以下哪句语句能顺利编译运行代码?
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.)
在命令行调用:
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);
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();
4.publicclassAbstractTestextendsAbstractIt{
5.privatefloatf1=1.0f;
6.privatefloatgetFloat(){returnf1;
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);
13.)
A.Compilationwillfail.
B.Compilationwillsucceedandtheprogramwillprint“0”
C.Compilationwillsucceedandtheprogramwillprint“1”
D.Compilationwillsucceedandtheprogramwillprint“2”
(26)
1.classsuper{
2.publicfloatgetNum(){return3.0f;
5.publicclassSubextendsSuper{
6.
哪个方法放在第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;
4.publicsuper(stringtext)(
5.I=1
7.)
8.
9.publicclasssubextendssuper(
10.publicsub(stringtext)(
11.i=2
12.)
14.publicstaticvoidmain(straingargs[])(
15.subsub=newsub(“Hello”);
16.system.out.PrintIn(sub.i);
17.)
18.)
B.程序输出“0”
C.程序输出“1”
D.程序输出“2”
(30)
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*;
3.publicclassXextendsFrame(
4.publicstaticvoidmain(st