1. given:
1. public class test ( 2. public static void main (string args[]) { 3. int i = 0xfffffff1; 4. int j = ~i; 5. 6. } 7. )
what is the decimal value of j at line 5?
a. 0 b. 1 c. 14 d. -15 e. an error at line 3 causes compilation to fail. f. an error at line 4 causes compilation to fail. //考点:按位取反的操作符使用
2. given:
integer i = new integer (42); long 1 = new long (42); double d = new double (42.0);
which two expressions evaluate to true? (choose two)
a. (i ==1) b. (i == d) c. (d == 1) d. (i.equals (d)) e. (d.equals (i)) f. (i.equals (42)) //考点:==和equals方法的区别
3. click the exhibit button:
1. public class test ( 2. private static int j = 0; 3. 4. private static boolean methodb(int k) ( 5. j = k; 6. return true; 7. ) 8. 9. public static void methoda(int i) { 10. boolean b: 11. b = i < 10 | methodb (4); 12. b = i < 10 || methodb (8); 13. ) 14. 15. public static void main (string args[] } ( 16. methoda (0); 17. system.out.printin(j); 18. ) 19. )
what is the result?
a. the program prints “0” b. the program prints “4” c. the program prints “8” d. the program prints “12” e. the code does not complete //考点:或运算和短逻辑或运算
4. given:
1.public class test ( 2. public static void main (string args[]) ( 3. system.out.printin (6 ^ 3); 4. ) 5.)
what is the output?
ans: //考点:异或的符号实际使用
5. 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. }
what is the result?
a. the code compiles and prints “a,b”. b. the code compiles and prints “a,a”. c. the code compiles and prints “b,b”. d. the code compiles and prints “ab,b”. e. the code compiles and prints “ab,ab”. f. the code does not compile BECause “ ” cannot be overloaded for stringbuffer. //考点:stringbuffer类的使用方法
6. click the exhibit button:
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.printin (textstring textbuffer); 18. } 19. )
what is the output? ans: //考点:string 和stringbuffer类的方法和使用
7. click the exhibit button:
1. public class test { 2. public static void add3 (integer i) } 3. int val = i.intvalue ( ); 4. val = 3; 5. i = new integer (val); 6. } 7. 8. public static void main (string args [ ] ) { 9. integer i = new integer (0); 10. add3 (i); 11. system.out.printin (i.intvalue ( ) ); 12. } 13. )
what is the result?
a. compilation will fail. b. the program prints “0”. c. the program prints “3”. d. compilation will succeed but an exception will be thrown at line 3. //考点:原始数据类型是传值的.
8. given:
1. public class constover { 2. public constover (int x, int y, int z) { 3. } 4. }
which two overload the constover constructor? (choose two)
a. constover ( ) { } b. protected int constover ( ) { } c. private constover (int z, int y, byte x) { } d. public object constover (int x, int y, int z) { } e. public void constover (byte x, byte y, byte z) { } //考点:构造器的重载问题
9. given:
1. public class methodover { 2. public void setvar (int a, int b, float c) { 3. } 4. }
which two overload the setvar method? (choose two)
a. private void setvar (int a, float c, int b) { } b. protected void setvar (int a, int b, float c) { } c. public int setvar (int a, float c, int b) (return a;) d. public int setvar (int a, int b, float c) (return a;) e. protected float setvar (int a, int b, float c) (return c;) //考点:方法的重载
10. given:
1. class baseclass { 2. private float x = 1.0f ; 3. protected float getvar ( ) ( return x;) 4. } 5. class subclass extends baseclass ( 6. private float x = 2.0f; 7. //insert code here 8. )
which two are valid examples of method overriding? (choose two)
a. float getvar ( ) { return x;} b. public float getvar ( ) { return x;} c. float double getvar ( ) { return x;} d. protected float getvar ( ) { return x;} e. public float getvar (float f ) { return f;} //考点:方法的覆盖
11. which two demonstrate an “is a” relationship? (choose two)
a. public interface person { } public class employee extends person { } b. public interface shape { } public class employee extends shape { } c. public interface color { } public class employee extends color { } d. public class species { } public class animal (private species species;) e. interface component { } class container implements component ( private component[ ] children; ) //考点:is a的关系问题
12. which statement is true?
a. an anonymous inner class may be declared as final b. an anonymous inner class can be declared as private c. an anonymous inner class can implement multiple interfaces d. an anonymous inner class can access final variables in any enclosing scope e. construction of an instance of a static inner class requires an instance of the enclosing outer class. //考点:匿名内部类的声明和存取问题
13. given:
1. package foo; 2. 3. public class outer ( 4. public static class inner ( 5. ) 6. )
which statement is true?
a. an instance of the inner class can be constructed with “new outer.inner ()” b. an instance of the inner class cannot be constructed outside of package foo c. an instance of the inner class can only be constructed from within the outer class d. from within the package bar, an instance of the inner class can be constructed with “new inner()”
//考点:内部类的实例化问题
14. click the exhibit button:
1. public class enclosingone ( 2. public class insideone{} 3. ) 4. public class inertest( 5. public static void main (string[]args)( 6. enclosingone eo= new enclosingone (); 7. //insert code here 8. ) 9. )
which statement at line 7 constructs an instance of the inner class?
a. insideonew ei= eo.new insideon();
b. eo.insideone ei = eo.new insideone();
c. insideone ei = enclosingone.new insideone();
d. enclosingone.insideone ei = eo.new insideone();
//考点:内部类的实例化问题
15. click the exhibit button:
1. interface foo { 2. int k = 0; 3. ] 4. 5. public class test implements foo ( 6. public static void main(string args[]) ( 7. int i; 8. test test = new test (); 9. i= test.k; 10. i= test.k; 11. i= foo.k; 12. ) 13. ) 14.
what is the result?
a. compilation succeeds.
16. given:
1. //point x
2. public class foo (
3. public static void main (string[]args) throws exception {
4. printwriter out = new printwriter (new
5. java.io.outputstreamwriter (system.out), true;
6. out.printin(“hello”);
7. }
8. )
which statement at pointx on line 1 allows this code to compile and run?
a. import java.io.printwriter;
b. include java.io.printwriter;
c. import java.io.outputstreamwriter;
d. include java.io.outputstreamwriter;
e. no statement is needed.
//考点:java源文件声明先后问题
17. which two statements are reserved words in java? (choose two)
a. run
b. import
c. default
d. implement
//考点:关键字的问题
18. which three are valid declarations of a float? (choose three)
a. float foo = -1;
b. float foo = 1.0;
c. float foo = 42e1;
d. float foo = 2.02f;
e. float foo = 3.03d;
f. float foo = 0x0123;
//考点:原始数据类型的声明问题及原始数据类型自动问题
19. given:
8. int index = 1;
9. boolean[] test = new boolean[3];
10. boolean foo= test [index];
what is the result?
a. foo has the value of 0
b. foo has the value of null
c. foo has the value of true
d. foo has the value of false
e. an exception is thrown
f. the code will not compile
//考点:boolean默认值的问题
20. given:
1. public class test(
2. public static void main(string[]args){
3. string foo = args [1];
4. string foo = args [2];
5. string foo = args [3];
6. }
7. }
and the command line invocation:
java test red green blue
what is the result?
a. baz has the value of “”
b. baz has the value of null
c. baz has the value of “red”
d. baz has the value of “blue”
e. bax has the value of “green”
f. the code does not compile
g. the program throws an exception
//考点:数组下标值问题
21. given:
8. int index = 1;
9. int [] foo = new int [3];
10. int bar = foo [index];
11. int baz = bar index;
what is the result?
a. baz has the value of 0
b. baz has the value of 1
c. baz has the value of 2
d. an exception is thrown
e. the code will not compile
//考点:数组使用问题
22. given:
1. public class foo {
2. public static void main (string[]args) {
3. string s;
4. system.out.printin (“s=” s);
5. }
6. }
what is the result?
a. the code compiles and “s=” is printed.
b. the code compiles and “s=null” is printed.
c. the code does not compile because string s is not initialized.
d. the code does not compile because string s cannot be referenced.
e. the code compiles, but a nullpointerexception is thrown when tostring is called.
//考点:引用型默认值问题问题
23. which will declare a method that forces a subclass to implement it?
a. public double methoda();
b. static void methoda (double d1) {}
c. public native double methoda();
d. abstract public void methoda();
e. protected void methoda (double d1){}
//考点:关键字使用问题
24. you want subclasses in any package to have access to members of a superclass. which is the most restrictive access modifier that will accomplish this objective?
a. public
b. private
c. protected
d. transient
e. no access modifier is qualified
//考点:关键字问题
25. given:
1. abstract class abstrctit {
2. abstract float getfloat ();
3. )
4. public class abstracttest extends abstractit {
5. private float f1= 1.0f;
6. private float getfloat () {return f1;}
7. }
what is the result?
a. compilation is successful.
b. an error on line 6 causes a runtime failure.
c. an error at line 6 causes compilation to fail.
d. an error at line 2 causes compilation to fail.
//考点:方法覆盖问题
26. click the exhibit button:
1. public class test( 2. public int amethod()[ 3. static int i=0; 4. i ; 5. return i; 6. ) 7. public static void main (string args[]){ 8. test test = new test(); 9. test.amethod(); 10. int j = test.amethod(); 11. system.out.printin(j); 12. ] 13. }
what is the result?
a. compilation will fail.
b. compilation will succeed and the program will print “0”.
c. compilation will succeed and the program will print “1”.
d. compilation will succeed and the program will print “2”.
//考点:static关键字问题
27. given:
1. class super {
2. public float getnum() {return 3.0f;}
3. )
4.
5. public class sub extends super {
6.
7. )
which method, placed at line 6, will cause a compiler error?
a. public float getnum() {return 4.0f; }
b. public void getnum () { }
c. public void getnum (double d) { }
d. public double getnum (float d) {retrun 4.0f; }
//考点:方法覆盖问题
28. which declaration prevents creating a subclass of an outer class?
a. static class foobar{}
b. private class foobar{}
c. abstract public class foobar{}
d. final public class foobar{}
e. final abstract class foobar{}
//考点:关键字使用问题
29. given:
1. byte [] arry1, array2[];
2. byte array3 [][];
3. byte[][] array4;
if each array has been initialized, which statement will cause a compiler error?
a. array2 = array1;
b. array2 = array3;
c. array2 = array4;
d. both a and b
e. both a and c
f. both b and c
//考点:数组声明问题
30. click the exhibit button:
1. class super ( 2. public int i = 0; 3. 4. public super (string text) ( 5. i = 1 6. ) 7. ) 8. 9. public class sub extends super ( 10. public sub (string text) ( 11. i= 2 12. ) 13. 14. public static void main (straing args[]) ( 15. sub sub = new sub (“hello”); 16. system.out. printin(sub.i); 17. ) 18. )
what is the result?
a. compilation will fail.
b. compilation will succeed and the program will print “0”.
c. compilation will succeed and the program will print “1”.
d. compilation will succeed and the program will print “2”.
//考点:方法覆盖问题
31. given:
1. public class returnit (
2. returntype methoda(byte x, double y) (
3. return (short) x/y * 2;
4. )
5. )
what is the valid returntype for methoda in line 2?
a. int
b. byte
c. long
d. short
e. float
f. double
//考点:操作符号执行顺序及原始数据类型自动转换问题
32. given the actionevent, which method allows you to identify the affected component?
a. getclass
b. gettarget
c. getsource
d. getcomponent
e. gettargetcomponent
//考点:awt问题
33. which is a method of the mousemotionlistener interface?
a. public void mousemoved(mouseevent)
b. public boolean mousemoved(mouseevent)
c. public void mousemoved(mousemotionevent)
d. public boolean mousemoved(mousemotionevent)
e. public boolean mousemoved(mousemotionevent)
//考点:awt问题
34. click the exhibit button:
1. import java.awt*; 2. 3. public class x extends frame ( 4. public static void main(string []args) ( 5. x x = new x (); 6. x.pack(); 7. x.setvisible(true); 8. ) 9. 10. public x () ( 11. setlayout (new gridlayout (2,2)); 12. 13. panel p1 = new panel(); 14. add(p1); 15. button b1= new button (“one”); 16. p1.add(b1); 17. 18. panel p2 = new panel(); 19. add(p2); 20. button b2= new button (“two”); 21. p2.add(b2); 22. 23. button b3= new button (“three”); 24. add(b3); 25. 26. button b4= new button (“four”); 27. add(b4); 28. ) 29. )
which two statements are true? (choose two)
a. all the buttons change height if the frame height is resized.
b. all the buttons change width if the frame width is resized.
c. the size of the button labeled “one” is constant even if the frame is resized.
d. both width and height of the button labeled “three” might change if the frame is resized.
//考点:awt问题
35. you are assigned the task of building a panel containing a textarea at the top, a label directly below it, and a button directly below the label. if the three components are added directly to the panel, which layout manager can the panel use to ensure that the textarea absorbs all of the free vertical space when the panel is resized?
a. gridlayout
b. cardlayout
a. string name= file.getparentname(“file.txt”);
b. string name= (new file(“file.txt”)).getparent();
c. string name = (new file(“file.txt”)).getparentname();
d. string name= (new file(“file.txt”)).getparentfile();
e. directory dir=(new file (“file.txt”)).getparentdir();
string name= dir.getname();
//考点:i/o问题
37. which can be used to encode chars for output?
a. java.io.outputstream
b. java.io.outputstreamwriter
c. java.io.encodeoutputstream
d. java.io.encodewriter
e. java.io.bufferedoutputstream
//考点:i/o问题
38. the file “file.txt” exists on the file system and contains ascii text.
given:
38. try {
39. file f = new file(“file.txt”);
40. outputstream out = new fileoutputstream(f, true);
41. }
42. catch (ioexception) {}
what is the result?
a. the code does not compile.
b. the code runs and no change is made to the file.
c. the code runs and sets the length of the file to 0.
d. an exception is thrown because the file is not closed.
e. the code runs and deletes the file from the file system.
//考点:i/o问题
39. which constructs a dataoutputstream?
a. new dataoutputstream(“out.txt”); a. outputstream out= new fileoutputstream (“file.txt”); 1. public class x ( when is the float object created in line 3, eligible for garbage collection?
a. just after line 5 3. string foo = “abcde”; type the value of foo at line 6.
ans:
//考点:string类方法使用问题 a. double d = math.cos(42); a. java.util.map a. the elements in the collection are ordered. 1. public class iftest ( what is the result? 47. click the exhibit button:
1. public class test ( 2. public static void main(string args[]) { 3. int 1= 0; 4. while (i) { 5. if (i==4) { 6. break; 7. ) 8. i; 9. ) 10. 11. ) 12. )
what is the value of i at line 10?
a. 0 3. int i= 1, j= 10 ; after execution, what are the values for i and j?
a. i = 6 and j= 5 1. switch (i) { what are the two acceptable types for the variable i? (choose two)
a. char 1. public class foo { what is the result?
a. the program runs and prints nothing. 1. import java.io.ioexception; 2. public class exceptiontest( 3. public static void main (string[]args) 4. try ( 5. methoda(); 6. ) catch (ioexception e) ( 7. system.out.printin(“caught ioexception”); 8. ) catch (exception e) ( 9. system.out.printin(“caught exception”); 10. ) 11. ) 12. public void methoda () { 13. throw new ioexception (); 14. ) 15. )
what is the result? 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 24?
ans:
//考点:try catch 例外捕捉问题 1. public class foo implements runnable ( what is the result? a. if only one thread is blocked in the wait method of an object, and another thread executes the modify on that same object, then the first thread immediately resumes execution. a. calling the yield method a. extend java.lang.thread and override the run method. 1. public class synctest ( under which conditions will check () return true when called from a different class?
a. check() can never return true 1. class a implements runable ( 2. int i; 3. public void run () ( 4. try ( 5. thread.sleep(5000); 6. i= 10; 7. ) catch(interruptedexception e) {} 8. ) 9. ) 10. 11. public class test { 12. public static void main (string args[]) ( 13. try ( 14. a a = new a (); 15. thread t = new thread (a); 16. t.start(); 17. 18. int j= a.i; 19. 20. ) catch (exception e) {} 21. ) 22. )
which statement al line 17 will ensure that j=10 at line 19?
a. a.wait(); 1. public class x implements runnable ( what is the result?
a.an error at line 11 causes compilation to fail. 1. public class synctest{ 2. public static void main(string[] args) { 3. final stringbuffer s1= new stringbuffer(); 4. final stringbuffer s2= new stringbuffer(); 5. new thread () { 6. public void run() { 7. synchronized(s1) { 8. s2.append(“a”); 9. synchronized(s2) { 10. s2.append(“b”); 11. system.out.print(s1); 12. system.out.print(s2); 13. } 14. } 15. } 16. }.start(); 17. new thread() { 18. public void run() { 19. synchronized(s2) { 20. s2.append(“c”); 21. synchronized(s1) { 22. s1.append(“d”); 23. system.out.print(s2); 24. system.out.print(s1); 25. } 26. } 27. } 28. }.start(); 29. } 30. }
which two statements are true? (choose two)
a. the program prints “abbcad” a. run(); 5. string foo = “base”; type the value of foo at line 8.
ans:
//考点:string类方法问题 a. int foo = (int) math.max(bar); a. a flow layout can be used to position a component that should resize horizontally when the container is resized. a. public class getclass() 1. import java.awt.*; 2. 3. public class test extends frame { 4. public test() { 5. add(new label(“hello”) ); 6. add(new textfield(“hello”) ); 7. add(new button(“hello”) ); 8. pack(); 9. show(); 10. } 11. 12. public static void main(string args[]) { 13. new test (); 14. } 15. )
what is the result?
a. the code will not compile. 1. class a { 2. public int getnumber(int a) { 3. return a 1; 4. } 5. } 6. 7. class b extends a { 8. public int getnumber (int a) { 9. return a 2 10. } 11. 12. public static void main (string args[]) { 13. a a = new b(); 14. system.out.printin(a.getnumber(0)); 15. } 16. }
what is the result?
a. compilation succeeds and 1 is printed. 1. class baseclass{ which two are valid examples of method overriding? (choose two)
a. void setvar(float f) {x = f;} a. an anonymous class can be declared as static. 1. class a { 2. public byte getnumber () { 3. return 1; 4. } 5. } 6. 7. class b extends a { 8. public short getnumber() { 9. return 2; 10. } 11. 12. public static void main (string args[]) { 13. b b = new b (); 14. system.out.printin(b.getnumber()) 15. } 16. }
what is the result?
a. compilation succeeds and 1 is printed. aninterface is an interface. which two construct an anonymous inner class? (choose two)
a. anadapter1 aa=new anadapter1(){} a. an inner class may be declared as static 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. a. public classone.java 1. package com.abc.pkg1; 2. public class classone { 3. private char var = ‘a’; 4. char getvar() {return var;} 5. } classtest.java 1. package com.abc.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 will fail. 1. public class arraytest { what is the result?
a. it prints f2[0] = 0.0. a. the default constructor initializes method variables. 1. class super { 2. public int getlength() {return 4;} 3. } 4. 5. public class sub extends super { 6. public long getlength() {return 5;} 7. 8. public static void main (string[]args) { 9. super sooper = new super (); 10. sub sub = new sub(); 11. system.out.printin( 12. sooper.getlength() “,” sub.getlength() }; 13. } 14. }
what is the output?
a. 4, 4 1. public abstract class test { which three changes (made independently) allow the code to compile? (choose three)
a. add a method body to methoda. a.boolean exists=directory.exists (“prefs”); a. inputstream in=new filereader(“file.txt”); a. outputstream out=new fileoutputstream(“file.txt”); a. new bufferedinputstream(“in.txt”); a. false 1. package foo; 2. 3. import java.util.vector; 4. 5. private class myvector extends vector { 6. int i = 1; 7. public myvector() { 8. i = 2; 9. } 10. } 11. 12. public class mynewvector extends myvector { 13. public mynewvector () { 14. i = 4; 15. } 16. public static void main (string args []) { 17. myvector v = new mynewvector(); 18. } 19. }
b. new dataoutputstream(new file(“out.txt”));
c. new dataoutputstream(new writer(“out.txt”));
d. new dataoutputstream(new filewriter(“out.txt”));
e. new dataoutputstream(new outputstream(“out.txt”));
f. new dataoutputstream(new fileoutputstream(“out.txt”));
//考点:i/o问题
40. what writes the text “
out.writebytes (“
b. outputstream os= new fileoutputstream (“file.txt”, true);
dataoutputstream out = new dataoutputstream(os);
out.writebytes (“
c. outputstream os= new fileoutputstream (“file.txt”);
dataoutputstream out = new dataoutputstream(os);
out.writebytes (“
d. outputstream os= new outputstream (“file.txt”, true);
dataoutputstream out = new dataoutputstream(os);
out.writebytes (“
//考点:i/o问题
41. given:
2. public object m () {
3. object o = new float (3.14f);
4. object [] oa = new object [1];
5. oa[0]= o;
6. o = null;
7. return oa[0];
8. }
9. }
b. just after line 6
c. just after line 7 (that is, as the method returns)
d. never in this method
//考点:垃圾收集问题
42. given:
4. foo.substring(3);
5. foo.concat(“xyz”);
6.
43. which method is an appropriate way to determine the cosine of 42 degrees?
b. double d = math.cosine(42);
c. double d = math.cos(math.toradians(42));
d. double d = math.cos(math.todegrees(42));
e. double d = math.cosine(math.toradians(42));
//考点:数学类使用问题
44. you need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. which interface provides that capability?
b. java.util.set
c. java.util.list
d. java.util.storedset
e. java.util.storedmap
f. java.util.collection
//考点:collection使用问题
45. which statement is true for the class java.util.hashset?
b. the collection is guaranteed to be immutable.
c. the elements in the collection are guaranteed to be unique.
d. the elements in the collection are accessed using a unique key.
e. the elements in the collections are guaranteed to be synchronized.
//考点:collection使用问题
46. given:
2. public static void main(string[]args) {
3. int x = 3;
4. int y = 1;
5. if (x = y)
6. system.out.printin(“not equal”);
7. else
8. system.out.printin(“equal”);
9. }
10. )
//考点:=不等于= =
a. the output is “equal”.
b. the output in “not equal”.
c. an error at line 5 causes compilation to fall.
d. the program executes but does not print a message.
b. 3
c. 4
d. 5
e. the code will not compile
//考点:循环嵌套问题
48. given:
4. do (
5. if (i > --j) continue;
6. ) while (i<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
//考点:循环嵌套问题
49. given:
2. default
3. system.out.printin(“hello”);
4. )
b. byte
c. float
d. double
e. object
//考点:关键字问题
50. given:
2. public static void main (string[]args)
3. try {return;}
4. finally {system.out.printin(“finally”);}
5. }
6. )
b. the program runs and prints “finally”.
c. the code compiles, but an exception is thrown at runtime.
d. the code will not compile because the catch block is missing.
//考点:try catch 例外捕捉执行顺序问题
51. click the exhibit button.
a. the code will not compile.
b. the output is caught exception.
c. the output is caught ioexception.
d. the program executes normally without printing a message.
//考点:try catch 例外捕捉顺序问题
52. click the exhibit button:
53. given:
2. public void run (thread t) {
3. system.out.printin(“running.”);
4. }
5. public static void main (string[] args) {
6. new thread (new foo()).start();
7. )
8. )
a. an exception is thrown
b. the program exists without printing anything
c. an error at line 1 causes compilation to fail.
d. an error at line 2 causes the compilation to fail.
e. “running” is printed and the program exits
//考点:线程启动方法
54. which statement is true?
b. if a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, it is still possible that the first thread might never resume execution.
c. if a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, then the first thread definitely resumes execution as a direct and sole consequence of the notify call.
d. if two threads are blocked in the wait method of one object, and another thread executes the notify method on the same object, then the first thread that executed the wait call first definitely resumes execution as a direct and sole consequence of the notify call.
//考点:线程方法问题
55. which two cannot directly cause a thread to stop executing? (choose two)
b. calling the wait method on an object
c. calling the notify method on an object
d. calling the notifyall method on an object
e. calling the start method on another thread object
//考点:线程方法问题
56. which two can be used to create a new thread? (choose two)
b. extend java.lang.runnable and override the start method.
c. implement java.lang.thread and implement the run method.
d. implement java.lang.runnable and implement the run method.
e. implement java.lang.thread and implement the start method.
//考点:创建线程方法问题
57. given:
2. private int x;
3. private int y;
4. private synchronized void setx (int i) (x=1;)
5. private synchronized void sety (int i) (y=1;)
6. public void setxy(int 1)(set x(i); sety(i);)
7. public synchronized boolean check() (return x !=y;)
8. )
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 only return true if synctest is changed to allow x and y to be set separately.
//考点:线程方法问题
58. click the exhibit button:
b. t.wait();
c. t.join();
d. t.yield();
e. t.notify();
f. a.notify();
g. t.interrupt();
//考点:线程方法问题
59. click the exhibit button:
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 synchronized void run( ) (
12. for (;(
13. x ;
14. y ;
15. system.out.printin(“x = “ x “, y = “ y);
16. )
17. )
18. )
b.errors at lines 7 and 8 cause compilation to fail.
c.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”)
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 twice (for example, “x=1, y=1” followed by “x=1, y=1”)
e.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 twice (for example, “x=1, y=1” followed by “x=2s, y=2”)
//考点:循环嵌套问题
60. which two cannot directly cause a thread to stop executing? (choose two)
a.existing from a synchronized block
b.calling the wait method on an object
c.calling notify method on an object
d.calling read method on an inputstream object
e.calling the setpriority method on a thread object
//考点:线程方法问题
61. click the exhibit button:
b. the program prints “cddacb”
c. the program prints “adcbadbc”
d. the output is a non-deterministic point because of a possible deadlock condition
e. the output is dependent on the threading model of the system the program is running on.
//考点:线程启动方法及string方法问题
62. which method in the thread class is used to create and launch a new thread of execution?
b. start();
c. execute();
d. run(runnable r);
e. start(runnable r);
f. execute(thread t);
//考点:线程启动方法问题
63. given:
6. foo.substring(0,3);
7. foo.concat(“ket”)
8.
64. which code determines the int value foo closest to, but not greater than, a double value 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);
//考点:数学类使用问题
65. which statement is true?
b. a grid layout can be used to position a component that should maintain a constant size even when the container is resized.
c. a border layout can be used to position a component that should maintain a constant size even when the container is resized.
d. the grid bag layout can be used to give a grid-like layout which differs from the normal grid in that individual rows and columns can have unique sizes.
e. if two components are placed in the same column of a grid bag layout, and one component resizes horizontally, then the other component must resize horizontally.
//考点:awt问题
66. given an actionevent, which method allows you to identify the affected component?
b. public object getsource()
c. public component getsource()
d. public component gettarget()
e. public component getcomponent()
f. public component gettargetcomponent()
//考点:awt问题
67. click the exhibit button:
b. a window will appear containing only a button.
c. an illegalargumentexception is thrown at line 6.
d. a window button will appear but will not contain the label, textfield, or button.
e. a window will appear containing a label at the top, a textfield below the label, and a button below the textfield.
f. a window will appear containing a label on the left, a textfield to the right of the label, and a button to the right of the textfield.
//考点:awt问题
68. click the exhibit button:
b. compilation succeeds and 2 is printed.
c. an error at line 8 causes compilation to fail.
d. an error at line 13 causes compilation to fail.
e. an error at line 14 causes compilation to fail.
//考点:方法覆盖及多态问题
69. given:
2. private float x= 1.0f;
3. protected void setvar (float f) {x = f;}
4. }
5. class subclass exyends baseclass {
6. private float x = 2.0f;
7. //insert code here
8. }
b. public void setvar(int f) {x = f;}
c. public void setvar(float f) {x = f;}
d. public double setvar(float f) {x = f;}
e. public final void setvar(float f) {x = f;}
f. protected float setvar() {x=3.0f; return 3.0f; }
//考点:方法覆盖问题
70. which statement about static inner classes is true?
b. a static inner class cannot be a static member of the outer class
c. a static inner class does not require an instance of the enclosing class.
d. instance members of a static inner class can be referenced using the class name of the static inner class.
//考点:内部类问题
71. click the exhibit button:
b. compilation succeeds and 2 is printed.
c. an error at line 8 causes compilation to fail.
d. an error at line 14 causes compilation to fail.
e. compilation succeeds but an exception is thrown at line 14.
//考点:方法覆盖问题
72. given:
anadapter0 is a non-abstract, non-final class with a zero argument constructor.
anadapter1 is a non-abstract, non-final class without a zero argument constructor, but with a constructor that takes one int argument.
b. anadapter0 aa=new anadapter0(){}
c. anadapter0 aa=new anadapter0(5){}
d. anadapter1 aa=new anadapter1(5){}
e. aninterface a1=new aninterface(5){}
//考点:适配器声明问题
73. which two statements are true? (choose two)
b. an anonymous inner class can be declared as public.
c. an anonymous inner class can be declared as private.
d. an anonymous inner class can extend an abstract class.
e. an anonymous inner class can be declared as protected.
//考点:匿名内部类问题
74. click the exhibit button:
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.
//考点:this引用问题
75. you want to limit access to a method of a public class to members of the same class. which access modifier accomplishes this objective?
b. private
c. protected
d. transient
e. no access modifier is required
//考点:关键字使用问题
76. click the exhibit button.
b. compilation succeeds and no exceptions are thrown.
c. compilation succeeds but an exception is thrown at line 5 in classtest.java.
d. compilation succeeds but an exception is thrown at line 6 in classtest.java.
//考点:类实例化问题问题
77. given:
2. public static void main (string[]args) {
3. float f1[], f2[];
4. f1 = new float [10];
5. f2 = f1;
6. system.out.printin (“f2[0]=” f2[0]);
7. }
8. }
b. it prints f2[0] = nan.
c. an error at line 5 causes compile to fail.
d. an error at line 6 causes compile to fail.
e. an error at line 6 causes an exception at runtime.
//考点:原始数据类型默认值问题
78. which two statements are true regarding the creation of a default constructor? (choose two)
b. the compiler always creates a default constructor for every class.
c. the default constructor invokes the no-parameter constructor of the superclass.
d. the default constructor initializes the instance variables declared in the class.
e. when a class has only constructors with parameters, the compiler does not create a default constructor.
//考点:默认构造方法问题
79. click the exhibit button:
b. 4, 5
c. 5, 4
d. 5, 5
e. the code will not compile
//考点:方法覆盖问题
80. given:
2. public abstract void methoda();
3.
4. public abstract void methodb()
5. {
6. system.out.printin(“hello”);
7. }
8. }
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 methodb.
e. remove the abstract qualifier from the declaration of methoda.
f. remove methodb in its entirely and change class o interface in line 1.
//考点:抽象类及抽象方法问题
81. which determines if “prefs” is a directory and exists on the file system?
b.boolean exists=(new file(“prefs”)).isdir();
c.boolean exists=(new directory(“prefs”)).exists();
d.boolean exists=(new file(“prefs”)).isdirectory();
e.boolean exists=true;
try{
directory d = new directory(“prefs”);
}
catch (filenotfoundexception e) {
exists = false;
}
//考点:i/o问题
82. which two create an inputstream and open file the “file.txt” for reading? (choose two)
b. inputstream in=new fileinputstream(“file.txt”);
c. inputstream in=new inputstreamfilereader (“file.txt”, “read”);
d. fileinputstream in=new filereader(new file(“file.txt”));
e. fileinputstream in=new fileinputstream(new file(“file.txt”));
//考点:i/o问题
83. which two construct an outputsream that appends to the file “file.txt”? (choose two)
b. outputstream out=new fileoutputstream(“file.txt”, “append”);
c. fileoutputstream out=new fileoutputstream(“file.txt”, true);
d. fileoutputstream out=new fileoutputstream(new file(“file.txt”));
e. outputstream out=new fileoutputstream(new file(“file.txt”)true);
//考点:i/o问题
84. which constructs a bufferedinputstream?
b. new bufferedinputstream(new file(“in.txt”));
c. new bufferedinputstream(new writer(“in.txt”));
d. new bufferedinputstream(new writer(“in.txt”));
e. new bufferedinputstream(new inputstream(“in.txt”));
f. new bufferedinputstream(new fileinputstream(“in.txt”));
//考点:i/o问题
85. which is a valid identifier?
b. default
c. _object
d. a-class
//考点:标识符问题
86. click the exhibit button: