JAVA基础部分面试千题库.doc

上传人:文库蛋蛋多 文档编号:4077570 上传时间:2023-04-03 格式:DOC 页数:330 大小:1.35MB
返回 下载 相关 举报
JAVA基础部分面试千题库.doc_第1页
第1页 / 共330页
JAVA基础部分面试千题库.doc_第2页
第2页 / 共330页
JAVA基础部分面试千题库.doc_第3页
第3页 / 共330页
JAVA基础部分面试千题库.doc_第4页
第4页 / 共330页
JAVA基础部分面试千题库.doc_第5页
第5页 / 共330页
点击查看更多>>
资源描述

《JAVA基础部分面试千题库.doc》由会员分享,可在线阅读,更多相关《JAVA基础部分面试千题库.doc(330页珍藏版)》请在三一办公上搜索。

1、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

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 +

3、 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 c

4、lass 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 Payloa

5、d(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 c

6、ode 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(S

7、tring 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: Proble

8、me)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 dura

9、tion 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 pos

10、sibility 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(En

11、d 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 (T

12、hread.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).wa

13、it().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(); . p

14、ublic 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();

15、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)

16、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

17、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);

18、 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 purpl

19、e = 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

20、 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 throw

21、n 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

22、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) r

23、eturn 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

24、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

25、 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

26、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

27、)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

28、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 succee

29、d.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

30、 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 clas

31、s 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 met

32、hods 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.f

33、ormat( 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 c

34、ode 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.appe

35、nd(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);

36、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)2

37、b)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.ClassCastExcep

38、tion( )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)0001202213

39、8)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)

40、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)

41、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 exce

42、ption.e)The code on line 33 executes successfully.41)10. int x = 0; int y = 10; do y-; +x; while (x 5); System.out.print(x + , + y);程序运行结果是( )a)5,6b)5,5c)6,5d)6,642)public class Drink public static void main(String args) boolean assertsOn = true; assert (assertsOn) : assertsOn = true; if(assertsOn) System.out.println(assert is on); 程序运行结果是( )a)no outputb)no output assert is onc)assert is ond)assert is on An As

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 办公文档 > 其他范文


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号