光庭公司在线Java笔试题

匿名网友 匿名网友 发布于: 2015-08-30 00:00:00
阅读 117 收藏 0 点赞 0 评论 0

一、单选题:【每题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.

15、下列运算符合法的是
A、 =
B、 &&
C、 <>
D、 if

16、选出下面哪个类可以被继承:
A、 java.lang.Thread
B、 java.lang.Math
C、 java.lang.Number
D、 java.lang.Double

17、Java是从( )语言改进重新设计。
A、 Ada
B、 BASIC
C、 C++
D、 Pasacal

18、以下代码::
1. public class A {
2. public void doit() {
3. }
4. public String doit() {
5. return “a”;
6. }
7. public double doit(int x) {
8. return 1.0;
9. }
10.}
下列哪一项是正确的:
A、 Compilation fails because of an error in line 7.
B、 Compilation succeeds and no runtime errors with class A occur.
C、 Compilation fails because of an error in line 4.
D、 An exception is thrown at runtime.

19、对于以下代码
20. public class CreditCard {
21.
22. private String cardlD;
23. private Integer limit;
24. public String ownerName;
25.
26. public void setCardlnformation(String cardlD,
27. String ownerName,
28. Integer limit) {
29. this.cardlD = cardlD;
30. this.ownerName = ownerName;
31. this.limit = limit;
32. }
33. }
正确的一项是:
A、 The ownerName variable breaks encapsulation.
B、 The code demonstrates polymorphism.
C、 The class is fully encapsulated.
D、 The cardlD and limit variables break polymorphism.

20、当浏览器第二次访问以下JSP网页时的输出结果是什么?
int b=0; a++; b++; %>
a:
b:
A、 a=2 b=1
B、 a=2 b=2
C、 a=0 b=0
D、 a=1 b=1

二、判断题:【每题2分】
1、public class Something {
public int addOne(final int x) {
return ++x;
}
}

2、short s1 = 1; s1 += 1
3、Servlet中,由表单提交来的请求用doPost()方法处理,由链接发起的请求用doGet()方法处理。
4、两个对象值相同(x.equals(y) == true),但却可有不同的hash code。
5、interface A{
int x = 0;
}
class B{
int x =1;
}
class C extends B implements A {
public void pX(){
System.out.println(x);
}
public static void main(String[] args) {
new C().pX();
}
}

6、public class Something {
public static void main(String[] args) {
Other o = new Other();
new Something().addOne(o);
}
public void addOne(final Other o) {
o.i++;
}
}
class Other {
public int i;
}

7、abstract class Something {
private abstract String doSomething ();
}

8、public class Something {
public static void main(String[] args) {
Other o = new Other();
new Something().addOne(o);
}
public void addOne(final Other o) {
o.i++;
}
}
class Other {
public int i;
}

9、abstract class Name {
private String name;
public abstract boolean isStupidName(String name) {}
}

10、public class Something {
void doSomething () {
private String s = “”;
int l = s.length();
}
}
三、问答题:【每题8分】
1、是否可以从一个static方法内部发出对非static方法的调用?
2、页面间对象传递的方法。
3、说说你所熟悉或听说过的j2ee中的几种常用模式?及对设计模式的一些看法。
4、说出Servlet的生命周期,并说出Servlet和CGI的区别。
5、什么时候用assert。

评论列表
文章目录