




已阅读5页,还剩325页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
java基础部分面试题库第一部分:选择题1)哪个不是面向对象的特征 ( )a)封装性b)继承性c)多态性d)健壮性2)编译java文件的命令是( )。a)javab)javacc)javadbd)javaw3)java源文件的扩展名是( )。a)classb)exec)java d)dll4)java内部使用的编码格式是( )。a)utf-8b)asciic)unicoded)iso8859-15)下列变量名称不合法的是( )a)indexb)$bc3&c)_cccded)34#bc56)下边对基本数据类型的说明正确的是( )a)int可以自动转换为byte类型b)double类型的数据占用2个字节c)java中一共有4类8种基本数据类型d)java中一共有3类8种基本数据类型7)下列不是java关键字的是( )a)gotob)ifc)countd)private8)下列变量声明中正确的是( )a)float f = 3.13 b)boolean b = 0c)int number = 5d)int x byte a = 9)public void go() string o = ; z: for(int x = 0; x 3; x+) for(int y = 0; y 2; y+) if(x=1) break; if(x=2 & y=1) break z; o = o + x + y; system.out.println(o); 程序的执行结果是( )a)00b)0001c)000120d)00012021e)compilation fails.f)an exception is thrown at runtime10)class payload private int weight; public payload (int w) weight = w; public void setweight(int w) weight = w; public string tostring() return integer.tostring(weight); public class testpayload static void changepayload(payload p) /* insert code */ public static void main(string args) payload p = new payload(200); p.setweight(1024); changepayload(p); system.out.println(p is + p); insert code处写入哪句话, 可以使程序的输出结果是420( )a)p.setweight(420);b)p.changepayload(420);c)p = new payload(420);d)payload.setweight(420);e)p = payload.setweight(420);11)void waitforsignal() object obj = new object(); synchronized (thread.currentthread() obj.wait(); obj.notify(); 这个程序片段的运行结果是什么( )a)this code can throw an interruptedexception.b)this code can throw an illegalmonitorstateexception.c)this code can throw a timeoutexception after ten minutes.d)reversing the order of obj.wait() and obj.notify() might cause this method to complete normally.12)public class threads2 implements runnable public void run() system.out.println(run.); throw new runtimeexception(problem); public static void main(string args) thread t = new thread(new threads2(); t.start(); system.out.println(end of method.); 运行结果是什么,请选择2个( )a)java.lang.runtimeexception: problemb)run. java.lang.runtimeexception: problemc)end of method. java.lang.runtimeexception: problemd)end of method. run. java.lang.runtimeexception: probleme)run. java.lang.runtimeexception: problem end of method.13)下边哪2句话的描述是正确的( )a)it is possible for more than two threads to deadlock at onceb)the jvm implementation guarantees that multiple threads cannot enter into a deadlocked state.c)deadlocked threads release once their sleep() methods sleep duration has expired.d)deadlocking can occur only when the wait(), notify(), and notifyall() methods are used incorrectly.e)it is possible for a single-threaded application to deadlock if synchronized blocks are used incorrectly.f)f a piece of code is capable of deadlocking, you cannot eliminate the possibility of deadlocking by inserting invocations of thread.yield().14)public class threads2 implements runnable public void run() system.out.println(run.); throw new runtimeexception(problem); public static void main(string args) thread t = new thread(new threads2(); t.start(); system.out.println(end of method.); 程序运行结果是,选择2个( )a)java.lang.runtimeexception: problem b)run. java.lang.runtimeexception: problem end of methodc)end of method. java.lang.runtimeexception: problemd)end of method. run. java.lang.runtimeexception: problem15) void waitforsignal() object obj = new object(); synchronized (thread.currentthread() obj.wait(); obj.notify(); 下列那句描述是正确的( )a)this code can throw an interruptedexception.b)this code can throw an illegalmonitorstateexception.c)this code can throw a timeoutexception after ten minutes.d)this code does not compile unless obj.wait() is replaced with (thread) obj).wait().16)11. class pingpong2 synchronized void hit(long n) for(int i = 1; i 3; i+) system.out.print(n + - + i + ); public class tester implements runnable static pingpong2 pp2 = new pingpong2(); public static void main(string args) new thread(new tester().start(); new thread(new tester().start(); . public void run() pp2.hit(thread.currentthread().getid(); 运行结果是( )a)the output could be 5-1 6-1 6-2 5-2b)the output could be 6-1 6-2 5-1 5-2c)the output could be 6-1 5-2 6-2 5-1d)the output could be 6-1 6-2 5-1 7-117)1. public class threads4 public static void main (string args) new threads4().go(); public void go() runnable r = new runnable() public void run() system.out.print(foo); ; thread t = new thread(r); t.start(); t.start(); 运行结果是( )a)compilation fails.b)an exception is thrown at runtime.c)the code executes normally and prints foo.d)the code executes normally, but nothing is printed.18)11. public class barn public static void main(string args) new barn().go(hi, 1); new barn().go(hi, world, 2); public void go(string. y, int x) system.out.print(yy.length - 1 + ); 运行结果是( )a)hi hib)hi worldc)compilation failsd)an exception is thrown at runtime.19)10. class nav . public enum direction north, south, east, west public class sprite / insert code here 哪句代码放到14行,程序可以正常编译( )a)direction d = north;b)nav.direction d = north;c)direction d = direction.north;d)nav.direction d = nav.direction.north;20)11. public class rainbow public enum mycolor red(0xff0000), green(0x00ff00), blue(0x0000ff); private final int rgb; mycolor(int rgb) this.rgb = rgb; public int getrgb() return rgb; ; public static void main(string args) / insert code here 哪句代码放到19行,程序可以正常编译( ) a)mycolor skycolor = blue;b)mycolor treecolor = mycolor.green;c)compilation fails due to other error(s) in the code.d)mycolor purple = mycolor.blue + mycolor.red;21)5. class atom atom() system.out.print(atom ); class rock extends atom rock(string type) system.out.print(type); public class mountain extends rock mountain() super(granite ); new rock(granite ); public static void main(string a) new mountain(); 运行结果是( )a)compilation failsb)atom granite granitec)an exception is thrown at runtime.d)atom granite atom granite22)1. interface testa string tostring(); public class test public static void main(string args) 4system.out.println(new testa() public string tostring() return test; 运行结果是( )a)testb)nullc)an exception is thrown at runtime.d)compilation fails because of an error in line 1.23)11. public static void parse(string str) try float f = float.parsefloat(str); catch (numberformatexception nfe) f = 0; finally 17. system.out.println(f); public static void main(string args) parse(invalid); 运行结果是( )a)0.0b)compilation fails.c)a parseexception is thrown by the parse method at runtimed)a numberformatexception is thrown by the parse method at runtime24)1. public class blip protected int blipvert(int x) return 0; class vert extends blip / insert code here 下列哪5个方法放到代码第五行,可以让程序编译正确,选择5个( )a)public int blipvert(int x) return 0; b)private int blipvert(int x) return 0; c)private int blipvert(long x) return 0; d)protected long blipvert(int x) return 0; e)protected int blipvert(long x) return 0; f)protected long blipvert(long x) return 0; g)protected long blipvert(int x, int y) return 0; 25)1. class super private int a; protected super(int a) this.a = a; . class sub extends super public sub(int a) super(a); public sub() this.a = 5; 下列哪2条语句是正确的( )a)change line 2 to: public int a;b)change line 2 to: protected int a;c)change line 13 to: public sub() this(5); d)change line 13 to: public sub() super(5); e)change line 13 to: public sub() super(a); 26) package test; class target public string name = hello; 如果可以直接修改和访问name这个变量,下列哪句话是正确的a)any classb)only the target classc)any class in the test packaged)any class that extends target27)11. abstract class vehicle public int speed() return 0; class car extends vehicle public int speed() return 60; class racecar extends car public int speed() return 150; . racecar racer = new racecar(); car car = new racecar(); vehicle vehicle = new racecar(); system.out.println(racer.speed() + , + car.speed() + , + vehicle.speed();运行结果是( )a)0, 0, 0b)150, 60, 0c)compilation failsd)150, 150, 150e)an exception is thrown at runtime28)5. class building public class barn extends building public static void main(string args) building build1 = new building(); barn barn1 = new barn(); barn barn2 = (barn) build1; object obj1 = (object) build1; string str1 = (string) build1; building build2 = (building) barn1; 15. 运行结果是( )a)if line 10 is removed, the compilation succeeds.b)if line 11 is removed, the compilation succeedsc)if line 12 is removed, the compilation succeeds.d)if line 13 is removed, the compilation succeeds.e)more than one line must be removed for compilation to succeed.29)29.given: class money private string country = canada; public string getc() return country; class yen extends money public string getc() return super.country; public class euro extends money public string getc(int x) return super.getc(); public static void main(string args) system.out.print(new yen().getc() + + new euro().getc(); 33. 运行结果是( )a)canadab)null canadac)canada nulld)compilation fails due to an error on line 26e)compilation fails due to an error on line 2930)13. import java.io.*; class food implements serializable int good = 3; class fruit extends food int juice = 5; public class banana extends fruit int yellow = 4; public static void main(string args) banana b = new banana(); banana b2 = new banana(); b.serializebanana(b); / assume correct serialization b2 = b.deserializebanana(); / assume correct system.out.println(restore +b2.yellow+ b2.juice+b2.good); / more banana methods go here 运行结果是( )a)restore 400b)restore 403c)restore 453d)compilation fails.e)an exception is thrown at runtime.31)11. double input = 314159.26; numberformat nf = numberformat.getinstance(locale.italian); string b; /insert code here下列哪条语句可以设置变量b的值为314.159,26( )a).b = nf.parse( input );b)b = nf.format( input );c)b = nf.equals( input );d)b = nf.parseobject( input );32)1. public class teststring1 public static void main(string args) string str = 420; str += 42; system.out.print(str); 7. 输出结果是( )a)42b)420c)462d)4204233)22. stringbuilder sb1 = new stringbuilder(123); string s1 = 123; / insert code here system.out.println(sb1 + + s1);下列哪句代码放到程序的第24行,可以输出123abc 123abc( )a)sb1.append(abc); s1.append(abc);b)sb1.append(abc); s1.concat(abc);c)sb1.concat(abc); s1.append(abc);d)sb1.concat(abc); s1.concat(abc);e)sb1.append(abc); s1 = s1.concat(abc);f)sb1.concat(abc); s1 = s1.concat(abc);g)sb1.append(abc); s1 = s1 + s1.concat(abc);34)1. public class lineup public static void main(string args) double d = 12.345; / insert code here 下列哪句代码放到程序的第4行,可以输出| 12.345|? ( )a)system.out.printf(|%7d| n, d);b)system.out.printf(|%7f| n, d);c)system.out.printf(|%3.7d| n, d);d)system.out.printf(|%3.7f| n, d);e)system.out.printf(|%7.3d| n, d);f)system.out.printf(|%7.3f| n, d);35)11. public class test public static void main(string args) int x = 5; boolean b1 = true; boolean b2 = false; if (x = 4) & !b2 )system.out.print(1 ); system.out.print(2 ); if (b2 = true) & b1 ) system.out.print(3 ); 程序的输出结果是( )a)2b)3c)1 2d)2 3e)1 2 3f)compilation fails.g)an exception is thrown at runtime.36)10. interface foo class alpha implements foo class beta extends alpha class delta extends beta public static void main( string args ) beta x = new beta(); / insert code here 18. 下列哪句代码放到第16行,可以导致一个java.lang.classcastexception( )a)alpha a = x;b)foo f = (delta)x;c)foo f = (alpha)x;d)beta b = (beta)(alpha)x;37)22. public void go() string o = ; z: . for(int x = 0; x 3; x+) for(int y = 0; y 2; y+) if(x=1) break; if(x=2 & y=1) break z; o = o + x + y; system.out.println(o); 当调用go方法时,输出结果是什么( )a)00b)0001c)000120d)00012022138)11. static void test() throws runtimeexception try system.out.print(test ); throw new runtimeexception(); catch (exception ex) system.out.print(exception ); public static void main(string args) try test(); catch (runtimeexception ex) system.out.print(runtime ); system.out.print(end ); 程序运行结果是( )a)test endb)compilation fails.c)test runtime endd)test exception ende).a throwable is thrown by main at runtime39)33. try / some code here catch (nullpointerexception e1) system.out.print(a); catch (exception e2) system.out.print(b); finally system.out.print(c); 如果程序的第34行会抛出一些异常,程序的运行结果是( )a)ab)bc)cd)ace)abc40)31. / some code here try / some code here catch (someexception se) / some code here finally / some code here 哪种情况下37行的代码会执行,请选择3个( )a)the instance gets garbage collected.b)the code on line 33 throws an exception.c)the code on line 35 throws an exception.d)the code on line 31 throws an exception.e)the code on line 33 executes successfully.41)10. int x = 0; int y = 10; do y-; +x; while (x 3) system.out.print(pi is bigger than 3. ); else system.out.print(pi is not bigger than 3. ); finally system.out.println(have a nice day.); 程序运行结果是( )a)compilation fails.b)pi is bigger than 3c)an exception occurs at runtime.d)pi is bigger than 3. have a nice day.e)pi is not bigger than 3. have a nice day.44)1. public class boxer1 integer i; int x; public boxer1(int y) x = i+y; system.out.println(x); public static void main(string args) new boxer1(new integer(4); 运行结果是( )a)the value 4 is printed at the command line.b)compilation fails because of an error in line 5.c)a nullpointerexception occurs at runtime.d)a numberformatexception occurs at runtime.45)1. public class person private string name; public person(string name) = name; public boolean equals(person p) return .equals(); 6. 7. 下列哪条语句是正确的( )a)the equals method does not properly override the object.equals method.b)compilation fails because the private attribute cannot be accessed in line 5.c)to work correctly with hash-based data structures, this class must also implement the hashcode method.d)when adding person objects to a java.util.set collection, the equals method in line 4 will prevent duplicates.46)1. public class score implements comparable private int wins, losses; public score(int w, int l) wins = w; losses = l; public int getwins() return wins; public int getlosses() return losses; public string tostring() return ; / inse
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 消防分区施工方案(3篇)
- 铜梁拓展公司活动策划方案(3篇)
- 铝板石材施工方案(3篇)
- 观看廉洁影片活动方案策划(3篇)
- 交通管道过路施工方案(3篇)
- 建房封顶施工方案(3篇)
- 北京市朝阳区2023-2024学年七年级上学期期中考试生物考题及答案
- 安徽省芜湖市南陵县2024-2025学年高二上学期第一次月考地理试题含参考答案
- 心理基础考试题目及答案
- 校园美食问答题目及答案
- 全国工会系统经审业务技能大赛知识题(附答案)
- GB/T 45745-2025道路货物运输车辆装载规范
- 2024年度可持续发展报告-泡泡玛特-
- 梯子安全培训
- 2025年剑桥商务英语(BEC)初级考试试卷全真模拟试题
- 小学劳动烹饪活动方案
- 呼吸衰竭个案护理
- 2025医德医风培训
- 教师安全培训会
- 合规财税培训课件
- 机械技术培训课件
评论
0/150
提交评论