logo资料库

光庭信息技术股份有限公司招聘JAVA笔试真题.doc

第1页 / 共13页
第2页 / 共13页
第3页 / 共13页
第4页 / 共13页
第5页 / 共13页
第6页 / 共13页
第7页 / 共13页
第8页 / 共13页
资料共13页,剩余部分请下载后查看
光庭信息技术股份有限公司招聘 JAVA 笔试真题 一、单选题:【每题 2 分】 1、如下代码: 23. Object [] myObjects = { 24. new integer(12), 25. new String(”foo”), 26. new integer(5), 27. new Boolean(true) 28. }; 29. Arrays.sort(myObjects); 30. for( int i=0; i 31. System.out.print(myObjects.toString()); 32. System.out.print(” “); 33. } A、 Compilation fails due to an error in line 29. B、 Compilation fails due to an error in line 23. C、 A ClassCastException occurs in line 29. D、 A ClassCastException occurs in line 31. 2、以下代码:: 1. class TestA { 2. public void start() { System.out.println(”TestA”); } 3. } 4. public class TestB extends TestA { 5. public void start() { System.out.println(”TestB”); } 6. public static void main(String[] args) { 7. ((TestA)new TestB()).start(); 8. } 9. } A、 An exception is thrown at runtime.
B、 TestA C、 TestB D、 Compilation fails. 3、11. public class Test { 12. public static void main(String [] args) { 13. int x =5; 14. boolean b1 = true; 15. boolean b2 = false; 16. 17. if((x==4) && !b2) 18. System.out.print(”l “); 19. System.out.print(”2 “); 20. if ((b2 = true) && b1) 21. System.out.print(”3 “); 22. } 23. } A、 2 3 B、 1 2 C、 2 D、 3 4、finally 块中的代码将 A、 异常没有发生时才被执行 B、 如果 try 块后面没有 catch 块时,finally 块中的代码才会执行 C、 总是被执行 D、 异常发生时才被执行 5、以下代码::
1. interface TestA { String toString(); } 2. public class Test { 3. public static void main(String[] args) { 4. System.out.println(new TestA() { 5. public String toString() { return “test”; } 6. }); 7. } 8. } 执行结果是: A、 Compilation fails because of an error in line 1. B、 An exception is thrown at runtime. C、 test D、 null 6、以下代码:: 11. public abstract class Shape { 12. int x; 13. int y; 14. public abstract void draw(); 15. public void setAnchor(int x, int y) { 16. this.x = x; 17. this.y = y; 18. } 19. } and a class Circle that extends and fully implements the Shape class. Which is correct? A、 Circle c = new Shape(); c.setAnchor(10,10); c.draw();
B、 Shape s = new Circle(); s->setAnchor(10,10); s->draw(); C、 Shape s = new Circle(); s.setAnchor(10,10); s.draw(); D、 Shape s = new Shape(); s.setAnchor(10,10); s.draw(); 7、以下代码:: 10. class One { 11. public One() { System.out.print(1); } 12. } 13. class Two extends One { 14. public Two() { System.out.print(2); } 15. } 16. class Three extends Two { 17. public Three() { System.out.print(3); } 18. } 19. public class Numbers{ 20. public static void main( String[] argv) { new Three(); } 21. } 执行结果是: A、 123 B、 3 C、 1 D、 321
8、下面哪个方法定义在接口中是有效的: A、 private void method1(); B、 final public void method4(); C、 public void method2(); D、 protected void method3(); 9、Given: 11. public enum Title { 12. MR(”Mr.”), MRS(”Mrs.”), MS(”Ms.”); 13. private final String title; 14. private Title(String t) { title = t; } 15. public String format(String last, String first) { 16. return title + “ “ + first + “ “ + last; 17. } 18. } 19. public static void main(String[] args) { 20. System.out.println(Title.MR.format(”Doe”, “John”)); 21. } 执行结果是: A、 Compilation fails because of an error in line 15. B、 An exception is thrown at runtime. C、 Compilation fails because of an error in line 12. D、 Mr. John Doe 10、以下代码:: 10. interface Foo { int bar(); } 11. public class Sprite { 12. public int fubar( Foo foo) { return foo.bar(); } 13. public void testFoo() {
14. fubar( 15. // insert code here 16. ); 17. } 18. } 下列哪行代码被插入到 14 行后,Sprite 类可以编译通过。 A、 new Foo { public int bar() { return 1; } } B、 Foo { public int bar() { return 1; } } C、 new class Foo { public int bar() { return 1; } } D、 newFoo() { public int bar(){return 1; } } 11、1. public interface A { 2. public void doSomething(String thing); 3. } 1. public class AImpl implements A { 2. public void doSomething(String msg) { } 3. } 1. public class B { 2. public A doit() { 3. // more code here 4. } 5. 6. public String execute() { 7. // more code here 8. } 9. } 1. public class C extends B { 2. public AImpl doit() { 3. // more code here
4. } 5. 6. public Object execute() { 7. // more code here 8. } 9. } 下列哪一项是正确的: A、 Compilation of class C will fail because of an error in line 6. B、 Compilation of class AImpl will fail because of an error in line 2. C、 Compilation of class C will fail because of an error in line 2. D、 Compilation will succeed for all classes and interfaces. 12、以下代码:: 11. public static void main(String[] args) { 12. Integer i = uew Integer(1) + new Integer(2); 13. switch(i) { 14. case 3: System.out.println(”three”); break; 15. default: System.out.println(”other”); break; 16. } 17. } 执行结果是: A、 three B、 Compilation fails because of an error on line 12 C、 An exception is thrown at runtime. D、 other 13、以下代码:: . package sun.scjp; public enum Color { RED, GREEN, BLUE }
1. package sun.beta; 2. // insert code here 3. public class Beta { 4. Color g = GREEN; 5. public static void main( String[] argv) 6. { System.out.println( GREEN); } 7. } 类 Beta 和 enum Color 在不同的包中,下列哪行代码被插入到第 2 行后,代码可以被编译通过: A、 import sun.scjp.Color; import static sun.scjp.Color.*; B、 import static sun.scjp.Color.*; C、 import sun.scjp.*; import static sun.scjp.Color.*; D、 import sun.scjp.Color.*; 14、以下代码:: 11. public void testIfA() { 12. if(testIfB(”True”)) { 13. System.out.println(”True”); 14. } else { 15. System.out.println(”Not true”); 16. } 17. } 18. public Boolean testIfB(String str) { 19. return Boolean.valueOf(str); 20. } 方法 testIfA 被调用后的结果是: A、 True B、 An exception is thrown at runtime. C、 Not true D、 Compilation fails because of an error at line 12.
分享到:
收藏