Posted in 面试题 onMarch 27, 2012
java笔试题目
QUESTION NO: 1
1. public class Test {
2. public static void main(String args[]) {
3. class Foo {
4. public int i = 3;
5. }
6. Object o = (Object)new Foo();
7. Foo foo = (Foo)o;
8. System.out.println(“i = “ + foo.i);
9. }
10. }
What is the result?
A. i = 3
B. Compilation fails.
C. A ClassCastException is thrown at line 6.
D. A ClassCastException is thrown at line 7.
QUESTION NO: 2
11. int i =1,j =10;
12. do {
13. if(i++> –j) {
14. continue;
15. }
16. } while (i 17. System.out.println(“i = “ +i+ “and j = “+j);
What is the result?
A. i = 6 and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 5
D. i = 5 and j = 6
E. i = 6 and j = 6
QUESTION NO: 3
Given:
1. class Test {
2. private Demo d;
3. void start() {
4. d = new Demo();
5. this.takeDemo(d);
6. }
7.
8. void takeDemo(Demo demo) {
9. demo = null;
10. demo = new Demo();
11. }
12. }
When is the Demo object, created on line 3, eligible for garbage collection?
A. After line 5.
B. After line 9.
C. After the start() method completes.
D. When the takeDemo() method completes.
E. When the instance running this code is made eligible for garbage collection.
QUESTION NO: 4
Given:
1. interface Animal {
2. void soundOff();
3. }
4.
5. class Elephant implements Animal {
6. public void soundOff() {
7. System.out.println(“Trumpet”);
8. }
9. }
10.
11. class Lion implements Animal {
12. public void soundOff() {
13. System.out.println(“Roar”);
14. }
15. }
16.
17. class Alpha1 {
18. static Animal get( String choice ) {
19. if ( choice.equalsIgnoreCase( “meat eater” )) {
20. return new Lion();
21. } else {
22. return new Elephant();
23. }
24. }
25. }
Which compiles?
A. new Animal().soundOff();
B. Elephant e = new Alpha1();
C. Lion 1 = Alpha.get(“meat eater”);
D. new Alpha1().get(“veggie”).soundOff();
QUESTION NO: 5
Given:
1. class A {
2. A() { }
3. }
4.
5. class B extends A {
6. }
Which two statements are true? (Choose two)
A. Class B’s constructor is public.
B. Class B’s constructor has no arguments.
C. Class B’s constructor includes a call to this().
D. Class B’s constructor includes a call to super().
QUESTION NO: 6
Given:
11. int i = 1,j = 10;
12. do {
13. if(i>j) {
14. break;
15. }
16. j–;
17. } while (++i 18. System.out.println(“i =” +i+” and j = “+j);
What is the result?
A. i = 6 and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 4
D. i = 5 and j = 6
E. i = 6 and j = 6
QUESTION NO: 7
1. class Super {
2. public float getNum() { return 3.0f; }
3. }
4.
5. public class Sub extends Super {.
7. }
Which method, placed at line6, causes compilation to fail?
A. public void getNum() { }
B. public void getNum(double d) { }
C. public float getNum() { return 4.0f; }
D. public double getNum(float d) { return 4.0d; }
QUESTION NO: 8
Which statement is true?
A. catch(X x) can catch subclasses of X.
B. The Error class is a RuntimeException.
C. Any statement that can throw an Error must be enclosed in a try block.
D. Any statement that can throw an Exception must be enclosed in a try block.
E. Any statement that can throw a RuntimeException must be enclosed in a try
block.
QUESTION NO: 9
Which three form part of correct array declarations? (Choose three)
A. public int a []
B. static int [] a
C. public [] int a
D. private int a [3]
E. private int [3] a []
F. public final int [] a
QUESTION NO: 10
1. public class Foo {
2. public static void main(String[] args) {
3. try {
4. return;
5. } finally {
6. System.out.println( “Finally” );
7. }
8. }
9. }
What is the result?
A. Finally
B. Compilation fails.
C. The code runs with no output.
D. An exception is thrown at runtime.
QUESTION NO: 11
Given:
ClassOne.java:
1. package com.abe.pkg1;
2. public class ClassOne {
3. private char var = ‘a’;
4. char getVar() { return var; }
5. }
ClassTest.java:
1. package com.abe.pkg2;
2. import com.abc.pkg1.ClassOne;
3. public class ClassTest extends ClassOne {
4. public static void main(String[] args) {
5. char a = new ClassOne().getVar();
6. char b = new ClassTest().getVar();
7. }
8. }
What is the result?
A. Compilation fails.
B. Compilation succeeds and no exceptions are thrown.
C. An exception is thrown at line 5 in ClassTest.java.
D. An exception is thrown at line 6 in ClassTest.java.
QUESTION NO: 12
Given:
1. class TestA {
2. TestB b;
3. TestA() {
4. b = new TestB(this);
5. }
6. }
7. class TestB {
8. TestA a;
9. TestB(TestA a) {
10. this.a = a;
11. }
12. }
13. class TestAll {
14. public static void main (String args[]) {
15. new TestAll().makeThings();
16. // …code continues on
17. }
18. void makeThings() {
19. TestA test = new TestA();
20. }
21. }
Which two statements are true after line 15, before main completes? (Choose two)
A. Line 15 causes a stack overflow.
B. An exception is thrown at runtime.
C. The object referenced by a is eligible for garbage collection.
D. The object referenced by b is eligible for garbage collection.
E. The object referenced by a is not eligible for garbage collection.
F. The object referenced by b is not eligible for garbage collection.
QUESTION NO: 13
Given:
1. public class ReturnIt {
2. return Type methodA(byte x, double y) {
3. return (long)x / y * 2;
4. }
5. }
What is the narrowest valid returnType for methodA in line2?
A. int
B. byte
C. long
D. short
E. float
F. double
QUESTION NO:14
Given:
1. public class OuterClass {
2. private double d1 = 1.0;
3. // insert code here
4. }
Which two are valid if inserted at line 3? (Choose two)
A. static class InnerOne {
public double methoda() { return d1; }
}
B. static class InnerOne {
static double methoda() { return d1; }
}
C. private class InnerOne {
public double methoda() { return d1; }
}
D. protected class InnerOne {
static double methoda() { return d1; }
}
E. public abstract class InnerOne {
public abstract double methoda();
}
QUESTION NO: 15
Given:
1. public abstract class Test {
2. public abstract void methodA();
3.
4. public abstract void methodB()
5. {
6. System.out.println(“Hello”);
7. }
8. }
Which two changes, independently applied, allow this code to compile? (Choose two)
A. Add a method body to methodA.
B. Replace lines 5 – 7 with a semicolon (“;”).
C. Remove the abstract qualifier from the declaration of Test.
D. Remove the abstract qualifier from the declaration of methodA.
E. Remove the abstract qualifier from the declaration of methodB.
QUESTION NO: 16
Given:
1. interface Beta {}
2.
3. class Alpha implements Beta {
4. String testIt() {
5. return “Tested”;
6. }
7. }
8.
9. public class Main1 {
10. static Beta getIt() {
11. return new Alpha();
12. }
13. public static void main( String[] args ) {
14. Beta b = getIt();
15. System.out.println( b.testIt() );
16. }
17. }
What is the result?
A. Tested
B. Compilation fails.
C. The code runs with no output.
D. An exception is thrown at runtime.
QUESTION NO: 17
Given:
1. public class Exception Test {
2. class TestException extends Exception {}
3. public void runTest() throws TestException {}
4. public void test() /* Point X */ {
5. runTest();
6. }
7. }
At Point X on line 4, which code is necessary to make the code compile?
A. No code is necessary.
B. throws Exception
C. catch ( Exception e )
D. throws RuntimeException
E. catch ( TestException e)
QUESTION NO: 18
Given that b and c refer to instances of wrapper classes, which two statements are
true? (Choose two)
A. b.equals(b) returns true.
B. b.equals(c) returns the same result as b == c.
C. b.eqials(c) can return false even if c.equals(b) returns true.
D. b.equals(c) throws an exception if b and c are different wrapper types.
E. b.equals(c) returns false if the type of wrapper objects being compared are
different.
QUESTION NO: 19
Given:
11. try {
12. if ((new Object))(.equals((new Object()))) {
13. System.out.println(“equal”);
14. )else{
15. System.out.println(“not equal”);
16. }
17. }catch (Exception e) {
18. System.out.println(“exception”);
19. }
What is the result?
A. equal
B. not equal
C. exception
D. Compilation fails.
QUESTION NO: 20
Given:
1. class BaseClass {
2. private float x = 1.of;
3. protected float getVar() { return x; }
4. }
5. class SubClass extends BaseClass {
6. private float x = 2.Of;
7. // insert code here
8. }
Which two are valid examples of method overriding when inserted at line 7? (Choose
two)
A. float getVar() { return x; }
B. public float getVar() { return x; }
C. public double getVar() { return x; }
D. protected float getVar() { return x; }
E. public float getVar(float f) { return f; }
QUESTION NO: 21
Given:
1. public class SyncTest {
2. private int x;
3. private int y;
4. private synchronized void setX( int i ) { x = i; }
5. private synchronized void setY( int i ) { y = i; }
6. public void setXY( int i ) { setX(i); setY(i); }
7. public synchronized boolean check() { return x != y; }
8. }
Under which condition will check return true when called from a different class?
A. check can never return true.
B. check can return true when setXY is called by multiple threads.
C. check can return true when multiple threads call setX and setY separately.
D. check can return true only if SyncTest is changed to allow x and y to be set
separately.
QUESTION NO: 22
Given:
1. public class X implements Runnable {
2. private int x;
3. private int y;
4.
5. public static void main(String [] args) {
6. X that = new X();
7. (new Thread( that )).start();
8. (new Thread( that )).start();
9. }
10.
11. public void run() {
12. for (;;) {
13. synchronized (this) {
14. x++;
15. y++;
16. }
17.
System.out.println(Thread.currentThread().getName() +
18. “x = “ + x + “, y = “ +
y);
19. }
20. }
21. }
What is the result?
A. Compilation fails.
B. The program prints pairs of values for x and y that might not always be the same on
the same line (for example, “x = 2, y = 1”).
C. The program prints pairs of values for x and y that are always the same on the same
line (for example, “x = 1, y = 1”).
In addition, each value appears only once (for example, “x = 1, y = 1” followed
by “x = 2, y = 2”).
The thread name at the start of the line shows that both threads are executing
concurrently.
D. The program prints pairs of values for x and y that are always the same on the same
line (for example, “x = 1, y = 1”).
In addition, each value appears only once (for example, “x = 1, y = 1” followed
by “x = 2, y = 2”).
The thread name at the start of the line shows that only a single thread is actually
executing.
QUESTION NO: 23
Given:
1. // Point X
2. public class foo {
3. public static void main(String[] args) throws Exception {
4. jave.io.PrintWriter out = new jave.io.PrintWriter(
5. new jave.io.OutputStreamWriter(System.out), true);
6. out.println(“Hello”);
7. }
8. }
Which statement at Point X on line 1 is required to allow this code to compile?
A. No statement is required.
B. import jave.io.*;
C. include java.io.*;
D. import jave.io.PrintWriter;
E. include java.io.PrintWriter;
QUESTION NO: 24
Which two are valid declarations of a float? (Choose two)
A. float f = 1F;
B. float f = 1.0.;
C. float f = ‘1’;
D. float f = “1”;
E. float f = 1.0d;
QUESTION NO: 25
What is the numerical range of a char?
A. 0 … 32767
B. 0 … 65535
310 – 035
Leading the way in IT testing and certification tools, www.testking.com
-65 -
C. –256 … 255
D. –32768 … 32767
E. Range is platform dependent.
QUESTION NO: 26
Which code determines the int value foo closest to, but not greater than, a double value
bar?
A. Int foo = (int) Math.max(bar);
B. Int foo = (int) Math.min(bar);
C. Int foo = (int) Math.abs(bar);
D. Int foo = (int) Math.ceil(bar);
E. Int foo = (int) Math.floor(bar);
F. Int foo = (int) Math.round(bar);
QUESTION NO: 27
Exhibit:
1. public class Mycircle {
2. public double radius;
3. public double diameter;
4.
5. public void setRadius(double radius)
6. this.radius = radius;
7. this.diameter= radius * 2;
8. }
9.
10. public double getRadius() {
11. return radius;
12. }
13. }
Which statement is true?
A. The Mycircle class is fully encapsulated.
B. The diameter of a given MyCircle is guaranteed to be twice its radius.
C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation.
D. The radius of a MyCircle object can be set without affecting its diameter.
QUESTION NO: 28
Which is a valid identifier?
A. false
B. default
C. _object
D. a-class
填空
QUESTION NO: 1
作用域public,private,protected,以及不写时的区别?
QUESTION NO: 2
Given:
11. int x = 3;
12. int y = 1;
13. if (x = y) {
14. System.out.println(“x = “ + x);
15. }
What is the result?
QUESTION NO: 3
Given:
1. public class Test {
2. public static void aMethod() throws Exception {
3. try {
4. throw new Exception();
5. } finally {
6. System.out.println(“finally”);
7. }
8. }
9. public static void main(String args[]) {
10. try {
11. aMethod();
12. } catch (Exception e) {
13. System.out.println(“exception”);
14. }
15. System.out.println(“finished”);
16. }
17. }
What is the result?
QUESTION NO: 4
1. public class Delta {
2. static boolean foo(char c) {
3. System.out.print(c);
4. return true;
5. }
6. public static void main( String[] argv ) {
7. int i =0;
8. for ( foo(‘A’); foo(‘B’)&&(i 9. i++ ;
10. foo(‘D’);
12. }
13. }
14. }
What is the result?
QUESTION NO: 5
1. public class SwitchTest {
2. public static void main(String[] args) {
3. System.out.println(“value = “ + switchIt(4));
4. }
5. public static int switchIt(int x) {
6. int j = 1;
7. switch (x) {
8. case 1: j++;
9. case 2: j++;
10. case 3: j++;
11. case 4: j++;
12. case 5: j++;
13. default: j++;
14. }
15. return j + x;
16. }
17. }
What is the result?
QUESTION NO: 6
Given:
1. public class Test {
2. public static String output =””;
3.
4. public static void foo(int i) {
5. try {
6. if(i==1) {
7. throw new Exception();
8. }
9. output += “1”;
10. }
11. catch(Exception e) {
12. output += “2”;
13. return;
14. }
15. finally {
16. output += “3”;
17. }
18. output += “4”;
19. }
20.
21. public static void main(String args[]) {
22. foo(0);
23. foo(1);
24.
25. }
26. }
What is the value of the variable output at line 23?
QUESTION NO: 7
Given:
1. public class X {
2. public static void main(String [] args) {
3. try {
4. badMethod();
5. System.out.print(“A”);
6. }
7. catch (Exception ex) {
8. System.out.print(“B”);
9. }
10. finally {
11. System.out.print(“C”);
12. }
13. System.out.print(“D”);
14. }
15. public static void badMethod() {}
17. }
What is the result?
QUESTION NO: 8
Given:
11. int i = 0;
12. while (true) {
13. if(i==4) {
14. break;
15. }
16. ++i;
17. }
18. System.out.println(“i=”+i);
What is the result?
QUESTION NO: 9
Given:
1. public class Alpha{
2. public static void main( string[] args ){
3. if ( args.length == 2 ) {
4. if ( args.[0].equalsIgnoreCase(“-b”) )
5. System.out.println( new Boolean( args[1] ));
6. }
7. }
8. }
And the code is invoked by using the command:
java Alpha –b TRUE
What is the result?
QUESTION NO: 10
Given:
11. String a = “ABCD”;
12. String b = a.toLowerCase();
13. b.replace(‘a’, ‘d’);
14. b.replace(‘b’, ‘c’);
15. System.out.println(b);
What is the result?
QUESTION NO: 11
Given:
1. public class Foo {
2. public static void main (String [] args) {
3. StringBuffer a = new StringBuffer (“A”);
4. StringBuffer b = new StringBuffer (“B”);
5. operate (a,b);
6. system.out.printIn{a + “,” +b};
7. )
8. static void operate (StringBuffer x, StringBuffer y) {
9. x.append {y};
10. y = x;
11. )
12. }
QUESTION NO: 12
Exhibit:
1. Public class test (
2. Public static void stringReplace (String text) (
3. Text = text.replace (‘j’ , ‘i’);
4. )
5.
6. public static void bufferReplace (StringBuffer text) (
7. text = text.append (“C”)
8. )
9.
10. public static void main (String args[]} (
11. String textString = new String (“java”);
12. StringBuffer text BufferString = new StringBuffer (“java”);
13.
14. stringReplace (textString);
15. bufferReplace (textBuffer);
16.
17. System.out.printLn (textString + textBuffer);
18. }
19. )
What is the output?
问答
1、jsp有哪些内置对象?作用分别是什么?
2、jsp有哪些动作?作用分别是什么?
3、JSP中动态INCLUDE与静态INCLUDE的区别?
4、Servlet的生命周期?
5、请写一个最基本的Servlet类
6、用JAVA实现一种排序?
QUESTION NO: 1
1. public class Test {
2. public static void main(String args[]) {
3. class Foo {
4. public int i = 3;
5. }
6. Object o = (Object)new Foo();
7. Foo foo = (Foo)o;
8. System.out.println(“i = “ + foo.i);
9. }
10. }
What is the result?
A. i = 3
B. Compilation fails.
C. A ClassCastException is thrown at line 6.
D. A ClassCastException is thrown at line 7.
QUESTION NO: 2
11. int i =1,j =10;
12. do {
13. if(i++> –j) {
14. continue;
15. }
16. } while (i 17. System.out.println(“i = “ +i+ “and j = “+j);
What is the result?
A. i = 6 and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 5
D. i = 5 and j = 6
E. i = 6 and j = 6
QUESTION NO: 3
Given:
1. class Test {
2. private Demo d;
3. void start() {
4. d = new Demo();
5. this.takeDemo(d);
6. }
7.
8. void takeDemo(Demo demo) {
9. demo = null;
10. demo = new Demo();
11. }
12. }
When is the Demo object, created on line 3, eligible for garbage collection?
A. After line 5.
B. After line 9.
C. After the start() method completes.
D. When the takeDemo() method completes.
E. When the instance running this code is made eligible for garbage collection.
QUESTION NO: 4
Given:
1. interface Animal {
2. void soundOff();
3. }
4.
5. class Elephant implements Animal {
6. public void soundOff() {
7. System.out.println(“Trumpet”);
8. }
9. }
10.
11. class Lion implements Animal {
12. public void soundOff() {
13. System.out.println(“Roar”);
14. }
15. }
16.
17. class Alpha1 {
18. static Animal get( String choice ) {
19. if ( choice.equalsIgnoreCase( “meat eater” )) {
20. return new Lion();
21. } else {
22. return new Elephant();
23. }
24. }
25. }
Which compiles?
A. new Animal().soundOff();
B. Elephant e = new Alpha1();
C. Lion 1 = Alpha.get(“meat eater”);
D. new Alpha1().get(“veggie”).soundOff();
QUESTION NO: 5
Given:
1. class A {
2. A() { }
3. }
4.
5. class B extends A {
6. }
Which two statements are true? (Choose two)
A. Class B’s constructor is public.
B. Class B’s constructor has no arguments.
C. Class B’s constructor includes a call to this().
D. Class B’s constructor includes a call to super().
QUESTION NO: 6
Given:
11. int i = 1,j = 10;
12. do {
13. if(i>j) {
14. break;
15. }
16. j–;
17. } while (++i 18. System.out.println(“i =” +i+” and j = “+j);
What is the result?
A. i = 6 and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 4
D. i = 5 and j = 6
E. i = 6 and j = 6
QUESTION NO: 7
1. class Super {
2. public float getNum() { return 3.0f; }
3. }
4.
5. public class Sub extends Super {.
7. }
Which method, placed at line6, causes compilation to fail?
A. public void getNum() { }
B. public void getNum(double d) { }
C. public float getNum() { return 4.0f; }
D. public double getNum(float d) { return 4.0d; }
QUESTION NO: 8
Which statement is true?
A. catch(X x) can catch subclasses of X.
B. The Error class is a RuntimeException.
C. Any statement that can throw an Error must be enclosed in a try block.
D. Any statement that can throw an Exception must be enclosed in a try block.
E. Any statement that can throw a RuntimeException must be enclosed in a try
block.
QUESTION NO: 9
Which three form part of correct array declarations? (Choose three)
A. public int a []
B. static int [] a
C. public [] int a
D. private int a [3]
E. private int [3] a []
F. public final int [] a
QUESTION NO: 10
1. public class Foo {
2. public static void main(String[] args) {
3. try {
4. return;
5. } finally {
6. System.out.println( “Finally” );
7. }
8. }
9. }
What is the result?
A. Finally
B. Compilation fails.
C. The code runs with no output.
D. An exception is thrown at runtime.
QUESTION NO: 11
Given:
ClassOne.java:
1. package com.abe.pkg1;
2. public class ClassOne {
3. private char var = ‘a’;
4. char getVar() { return var; }
5. }
ClassTest.java:
1. package com.abe.pkg2;
2. import com.abc.pkg1.ClassOne;
3. public class ClassTest extends ClassOne {
4. public static void main(String[] args) {
5. char a = new ClassOne().getVar();
6. char b = new ClassTest().getVar();
7. }
8. }
What is the result?
A. Compilation fails.
B. Compilation succeeds and no exceptions are thrown.
C. An exception is thrown at line 5 in ClassTest.java.
D. An exception is thrown at line 6 in ClassTest.java.
QUESTION NO: 12
Given:
1. class TestA {
2. TestB b;
3. TestA() {
4. b = new TestB(this);
5. }
6. }
7. class TestB {
8. TestA a;
9. TestB(TestA a) {
10. this.a = a;
11. }
12. }
13. class TestAll {
14. public static void main (String args[]) {
15. new TestAll().makeThings();
16. // …code continues on
17. }
18. void makeThings() {
19. TestA test = new TestA();
20. }
21. }
Which two statements are true after line 15, before main completes? (Choose two)
A. Line 15 causes a stack overflow.
B. An exception is thrown at runtime.
C. The object referenced by a is eligible for garbage collection.
D. The object referenced by b is eligible for garbage collection.
E. The object referenced by a is not eligible for garbage collection.
F. The object referenced by b is not eligible for garbage collection.
QUESTION NO: 13
Given:
1. public class ReturnIt {
2. return Type methodA(byte x, double y) {
3. return (long)x / y * 2;
4. }
5. }
What is the narrowest valid returnType for methodA in line2?
A. int
B. byte
C. long
D. short
E. float
F. double
QUESTION NO:14
Given:
1. public class OuterClass {
2. private double d1 = 1.0;
3. // insert code here
4. }
Which two are valid if inserted at line 3? (Choose two)
A. static class InnerOne {
public double methoda() { return d1; }
}
B. static class InnerOne {
static double methoda() { return d1; }
}
C. private class InnerOne {
public double methoda() { return d1; }
}
D. protected class InnerOne {
static double methoda() { return d1; }
}
E. public abstract class InnerOne {
public abstract double methoda();
}
QUESTION NO: 15
Given:
1. public abstract class Test {
2. public abstract void methodA();
3.
4. public abstract void methodB()
5. {
6. System.out.println(“Hello”);
7. }
8. }
Which two changes, independently applied, allow this code to compile? (Choose two)
A. Add a method body to methodA.
B. Replace lines 5 – 7 with a semicolon (“;”).
C. Remove the abstract qualifier from the declaration of Test.
D. Remove the abstract qualifier from the declaration of methodA.
E. Remove the abstract qualifier from the declaration of methodB.
QUESTION NO: 16
Given:
1. interface Beta {}
2.
3. class Alpha implements Beta {
4. String testIt() {
5. return “Tested”;
6. }
7. }
8.
9. public class Main1 {
10. static Beta getIt() {
11. return new Alpha();
12. }
13. public static void main( String[] args ) {
14. Beta b = getIt();
15. System.out.println( b.testIt() );
16. }
17. }
What is the result?
A. Tested
B. Compilation fails.
C. The code runs with no output.
D. An exception is thrown at runtime.
QUESTION NO: 17
Given:
1. public class Exception Test {
2. class TestException extends Exception {}
3. public void runTest() throws TestException {}
4. public void test() /* Point X */ {
5. runTest();
6. }
7. }
At Point X on line 4, which code is necessary to make the code compile?
A. No code is necessary.
B. throws Exception
C. catch ( Exception e )
D. throws RuntimeException
E. catch ( TestException e)
QUESTION NO: 18
Given that b and c refer to instances of wrapper classes, which two statements are
true? (Choose two)
A. b.equals(b) returns true.
B. b.equals(c) returns the same result as b == c.
C. b.eqials(c) can return false even if c.equals(b) returns true.
D. b.equals(c) throws an exception if b and c are different wrapper types.
E. b.equals(c) returns false if the type of wrapper objects being compared are
different.
QUESTION NO: 19
Given:
11. try {
12. if ((new Object))(.equals((new Object()))) {
13. System.out.println(“equal”);
14. )else{
15. System.out.println(“not equal”);
16. }
17. }catch (Exception e) {
18. System.out.println(“exception”);
19. }
What is the result?
A. equal
B. not equal
C. exception
D. Compilation fails.
QUESTION NO: 20
Given:
1. class BaseClass {
2. private float x = 1.of;
3. protected float getVar() { return x; }
4. }
5. class SubClass extends BaseClass {
6. private float x = 2.Of;
7. // insert code here
8. }
Which two are valid examples of method overriding when inserted at line 7? (Choose
two)
A. float getVar() { return x; }
B. public float getVar() { return x; }
C. public double getVar() { return x; }
D. protected float getVar() { return x; }
E. public float getVar(float f) { return f; }
QUESTION NO: 21
Given:
1. public class SyncTest {
2. private int x;
3. private int y;
4. private synchronized void setX( int i ) { x = i; }
5. private synchronized void setY( int i ) { y = i; }
6. public void setXY( int i ) { setX(i); setY(i); }
7. public synchronized boolean check() { return x != y; }
8. }
Under which condition will check return true when called from a different class?
A. check can never return true.
B. check can return true when setXY is called by multiple threads.
C. check can return true when multiple threads call setX and setY separately.
D. check can return true only if SyncTest is changed to allow x and y to be set
separately.
QUESTION NO: 22
Given:
1. public class X implements Runnable {
2. private int x;
3. private int y;
4.
5. public static void main(String [] args) {
6. X that = new X();
7. (new Thread( that )).start();
8. (new Thread( that )).start();
9. }
10.
11. public void run() {
12. for (;;) {
13. synchronized (this) {
14. x++;
15. y++;
16. }
17.
System.out.println(Thread.currentThread().getName() +
18. “x = “ + x + “, y = “ +
y);
19. }
20. }
21. }
What is the result?
A. Compilation fails.
B. The program prints pairs of values for x and y that might not always be the same on
the same line (for example, “x = 2, y = 1”).
C. The program prints pairs of values for x and y that are always the same on the same
line (for example, “x = 1, y = 1”).
In addition, each value appears only once (for example, “x = 1, y = 1” followed
by “x = 2, y = 2”).
The thread name at the start of the line shows that both threads are executing
concurrently.
D. The program prints pairs of values for x and y that are always the same on the same
line (for example, “x = 1, y = 1”).
In addition, each value appears only once (for example, “x = 1, y = 1” followed
by “x = 2, y = 2”).
The thread name at the start of the line shows that only a single thread is actually
executing.
QUESTION NO: 23
Given:
1. // Point X
2. public class foo {
3. public static void main(String[] args) throws Exception {
4. jave.io.PrintWriter out = new jave.io.PrintWriter(
5. new jave.io.OutputStreamWriter(System.out), true);
6. out.println(“Hello”);
7. }
8. }
Which statement at Point X on line 1 is required to allow this code to compile?
A. No statement is required.
B. import jave.io.*;
C. include java.io.*;
D. import jave.io.PrintWriter;
E. include java.io.PrintWriter;
QUESTION NO: 24
Which two are valid declarations of a float? (Choose two)
A. float f = 1F;
B. float f = 1.0.;
C. float f = ‘1’;
D. float f = “1”;
E. float f = 1.0d;
QUESTION NO: 25
What is the numerical range of a char?
A. 0 … 32767
B. 0 … 65535
310 – 035
Leading the way in IT testing and certification tools, www.testking.com
-65 -
C. –256 … 255
D. –32768 … 32767
E. Range is platform dependent.
QUESTION NO: 26
Which code determines the int value foo closest to, but not greater than, a double value
bar?
A. Int foo = (int) Math.max(bar);
B. Int foo = (int) Math.min(bar);
C. Int foo = (int) Math.abs(bar);
D. Int foo = (int) Math.ceil(bar);
E. Int foo = (int) Math.floor(bar);
F. Int foo = (int) Math.round(bar);
QUESTION NO: 27
Exhibit:
1. public class Mycircle {
2. public double radius;
3. public double diameter;
4.
5. public void setRadius(double radius)
6. this.radius = radius;
7. this.diameter= radius * 2;
8. }
9.
10. public double getRadius() {
11. return radius;
12. }
13. }
Which statement is true?
A. The Mycircle class is fully encapsulated.
B. The diameter of a given MyCircle is guaranteed to be twice its radius.
C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation.
D. The radius of a MyCircle object can be set without affecting its diameter.
QUESTION NO: 28
Which is a valid identifier?
A. false
B. default
C. _object
D. a-class
填空
QUESTION NO: 1
作用域public,private,protected,以及不写时的区别?
QUESTION NO: 2
Given:
11. int x = 3;
12. int y = 1;
13. if (x = y) {
14. System.out.println(“x = “ + x);
15. }
What is the result?
QUESTION NO: 3
Given:
1. public class Test {
2. public static void aMethod() throws Exception {
3. try {
4. throw new Exception();
5. } finally {
6. System.out.println(“finally”);
7. }
8. }
9. public static void main(String args[]) {
10. try {
11. aMethod();
12. } catch (Exception e) {
13. System.out.println(“exception”);
14. }
15. System.out.println(“finished”);
16. }
17. }
What is the result?
QUESTION NO: 4
1. public class Delta {
2. static boolean foo(char c) {
3. System.out.print(c);
4. return true;
5. }
6. public static void main( String[] argv ) {
7. int i =0;
8. for ( foo(‘A’); foo(‘B’)&&(i 9. i++ ;
10. foo(‘D’);
12. }
13. }
14. }
What is the result?
QUESTION NO: 5
1. public class SwitchTest {
2. public static void main(String[] args) {
3. System.out.println(“value = “ + switchIt(4));
4. }
5. public static int switchIt(int x) {
6. int j = 1;
7. switch (x) {
8. case 1: j++;
9. case 2: j++;
10. case 3: j++;
11. case 4: j++;
12. case 5: j++;
13. default: j++;
14. }
15. return j + x;
16. }
17. }
What is the result?
QUESTION NO: 6
Given:
1. public class Test {
2. public static String output =””;
3.
4. public static void foo(int i) {
5. try {
6. if(i==1) {
7. throw new Exception();
8. }
9. output += “1”;
10. }
11. catch(Exception e) {
12. output += “2”;
13. return;
14. }
15. finally {
16. output += “3”;
17. }
18. output += “4”;
19. }
20.
21. public static void main(String args[]) {
22. foo(0);
23. foo(1);
24.
25. }
26. }
What is the value of the variable output at line 23?
QUESTION NO: 7
Given:
1. public class X {
2. public static void main(String [] args) {
3. try {
4. badMethod();
5. System.out.print(“A”);
6. }
7. catch (Exception ex) {
8. System.out.print(“B”);
9. }
10. finally {
11. System.out.print(“C”);
12. }
13. System.out.print(“D”);
14. }
15. public static void badMethod() {}
17. }
What is the result?
QUESTION NO: 8
Given:
11. int i = 0;
12. while (true) {
13. if(i==4) {
14. break;
15. }
16. ++i;
17. }
18. System.out.println(“i=”+i);
What is the result?
QUESTION NO: 9
Given:
1. public class Alpha{
2. public static void main( string[] args ){
3. if ( args.length == 2 ) {
4. if ( args.[0].equalsIgnoreCase(“-b”) )
5. System.out.println( new Boolean( args[1] ));
6. }
7. }
8. }
And the code is invoked by using the command:
java Alpha –b TRUE
What is the result?
QUESTION NO: 10
Given:
11. String a = “ABCD”;
12. String b = a.toLowerCase();
13. b.replace(‘a’, ‘d’);
14. b.replace(‘b’, ‘c’);
15. System.out.println(b);
What is the result?
QUESTION NO: 11
Given:
1. public class Foo {
2. public static void main (String [] args) {
3. StringBuffer a = new StringBuffer (“A”);
4. StringBuffer b = new StringBuffer (“B”);
5. operate (a,b);
6. system.out.printIn{a + “,” +b};
7. )
8. static void operate (StringBuffer x, StringBuffer y) {
9. x.append {y};
10. y = x;
11. )
12. }
QUESTION NO: 12
Exhibit:
1. Public class test (
2. Public static void stringReplace (String text) (
3. Text = text.replace (‘j’ , ‘i’);
4. )
5.
6. public static void bufferReplace (StringBuffer text) (
7. text = text.append (“C”)
8. )
9.
10. public static void main (String args[]} (
11. String textString = new String (“java”);
12. StringBuffer text BufferString = new StringBuffer (“java”);
13.
14. stringReplace (textString);
15. bufferReplace (textBuffer);
16.
17. System.out.printLn (textString + textBuffer);
18. }
19. )
What is the output?
问答
1、jsp有哪些内置对象?作用分别是什么?
2、jsp有哪些动作?作用分别是什么?
3、JSP中动态INCLUDE与静态INCLUDE的区别?
4、Servlet的生命周期?
5、请写一个最基本的Servlet类
6、用JAVA实现一种排序?
益模软件Java笔试题
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Tags in this post...
Reply on: @reply_date@
@reply_contents@