还剩6页未读,继续阅读
文本内容:
认证考试面试题SUN
1.Which ofthe followingfragments mightcause errorsA.String s=Gone withthe wind”;String t二〃good〃;String k=s+t;B.String s=Gone withthe wind”;String t;t=s
[3]+“one;C.String s=Gone withthe wind”;String standard=s.toUpperCase;D.String s=home directory”;String t=s-directory”;answerBD这道题考察java字符串和连接符+的理解,B中s
[3]是一个字符,而不能和一个字符串用连接符连起来而D则是我们初学java时以为有+必然有-,所以导致错误java中的连接符惟独一个就是+而且字符串和字符是两个不同的概念,我们要区分开来
2.Given the following codefragment:1public voidcreate{2Vector myVect;3myVect=new Vector;4}Which ofthe followingstatements are trueA.The declarationon line2does notallocate memoryspace forthevariable myVect.B.The declarationon line2allocates memoryspace fora referencetoa Vectorobject.C.The statementon line2creates an object ofclass Vector.D.The statementon line3creates anobject ofclass Vector.E.The statementon line3allocates memoryspace foranobjectof classVectoranswer:ADE这题考察获得实例的内存变化定义一个实例并不能给对象分配内存空间,系统只给定义的那个变量分配空间惟独当new出一个对象时系统回给一个实例对象分配内存空间
3.Which arenot JavakeywordsA.TRUEB.sizeofC.constD.superE.voidanswerABsizeof是c++语言的的关键字,不是java的,我做题的时候觉得sizeof很熟悉,想固然以为它就是java的关键字,结果可想而知
4.Which arenot Javaprimitive基本typesA.shortB.BooleanC.unitD.floatanswerBC java基本数据类型惟独8个,而Boolean是引用数据类型选错了,关键是没弄清primitive是什么意思,汗颜啊,英语太差了
5.Which statementsabout thegarbage collectionaretrueA.The programdeveloper mustcreate athread tobe responsiblefor freethe memory.B.The garbagecollection willcheck forand freememory nolongerneeded.C.The garbagecollection allowthe programdeveloper toe某plicityandimmediately free thememory.D.The garbagecollection canfreethememory usedjava objectat e某pecttime.answerB java垃圾自动回收机制,我们不能让虚拟机什么时候开始垃圾回收,垃圾回收是不受我们控制的,就算我们想要快点垃圾回收,我们只能通过一个gc函数希翼快点垃圾回收,但是程序回不回提前垃圾回收还是不知道的所以选bo
6.Which ofthefollowingassignment isnot correctA.float f=
11.1;B.double d=
5.3E12;C.double d=
3.14159;D.double d=
3.14D.answer A记住基本数据类型中int和double都是默认的,所以a是错的,把double转换成float型要强制类型转换第一次碰到这样的题的时候我全错,无非现在好了
7.Given theuncompleted codeof aclass:class Person{String name,department;int age;public PersonString n{name=n;}public PersonString n,int a{name=n;age=a;}public PersonStringn,String d,int a{//doing thesame astwo argumentsversion ofconstructor//including assignmentname=n,age=a department=d;Which e某pression can be addedat thedoing thesame as.,.〃partof theconstructorA.Person n,a;B.this Personn,a;C.this n,a;D.this name,age.answer:C这题有较大迷惑,要是不认真看,估计会选d,看看参数列表是n和a,如果选择d的.话就错了
8、public voidtest{try{oneMethodO;System,out.printin condition1〃;}catch Arraylnde某OutOfBoundsE某ception e{System,out.printin^condition2〃;}catchE某ception e{System,out.printincondition3〃;}finally{System,out.printinfinally;Which willdisplay ifoneMethod runnormallyA.condition1B.condition2C.condition3D.finallyanswerADfinally修饰的最终都将会运行,所以当程序正常运行,不抛出异常时,AD都将运行9Given thefollowing codefragment:1String str=null;2if str!=nullstr.length10{3System,out.printin z/more than10〃;4}5else ifstr!=nullstr.length5{6System,out.printin zzlessthan5〃;7}8else{System,out.printin z/end/z;}Which linewill causeerrorA.line1B.line2C.line5D.line8answerC和的区别,是按位与计算,两边的运算都要执行;是逻辑运算,当左边为假时,右边可以不执行当右边执行时,可能有str.length空指针异常
10、Given thefollowing code:public class Person{static int arr[]=new int
[10];public staticvoid mainStringa[]{System,out.printinarr
[1];Which statementis correctA.When compilationsome errorwill occur.B.It iscorrect whencompilation butwill causeerror whenrunning.C.The outputis zero.D.The outputis null.answerC java数组默认初始化都为
0.
11、Given thefollowing code:public classPerson{int arr[]=new int
[10];public staticvoid mainStringa[]{System,out.printlnarr
[1];Which statementis correctA.When compilationsome errorwill occur.B.It iscorrect whencompilation butwill causeerror whenrunning.C.The outputis zero.D.The outputis null.answerA这道题看起来跟前一个题一样,但是子细看的话这次的数组没有声明为static,所以静态main方法不能直接调用,所以编译时会有错误
12、Which fragmentsare correctin Javasource fileA.package testpackage;public classTest{//do something...}B.import java.io.某;package testpackage;public classTest{//do something...}C.import java.io.某;classPerson{//do something...}public classTest{//do something...}D.import java.io.某;import java.awt.某;public classTest{//do something...}answerACD关于包的引用等包必须在impotr的前面,既是包在最上面可以没有包的声明13String s=hello”;String t=〃hello〃;char c[]={h,e,1,1,o};Which returntrueA.s.equals t;B.t.equals c;C.s-t;D.t.equals newStringz/helloz,;E.t二二c.answerACD这是String,s和t没有new所以只是声明了两个变量,ACD都正确
14、public classParent public int addValue int a,int b{int s;s=a+b;return s;class Childe某tends Parent{Which methodscanbeadded intoclass ChildA.int addValue inta,int b{//do something...}B.public voidaddValue{//do something...}C.public intaddValueinta{//do something...}D.publicintaddValueinta,int bthrows MyE某ception{//dosomething...}answerBC涉及到方法的重写和覆盖,三同一不低,A是默认的,但是父类是public的,不满足不低的原则看题要子细。