[这个贴子最后由jerryr在 2002/02/22 01:40pm 编辑]
看到不少人想要scjp的资料,我是在2001年8月过的scjp,通过率88%,考前用的一套试题,在考试时有6成是原题,不知道现在的题库变了没有。
但是这104到题中所涉及的知识如果都弄懂的话,相信通过是没有任何问题的。(考试时基本上所有的题都是选择题)
下面附上试题及答案,祝大家考试愉快!!(如果觉得还行,请跟贴)
-----------------------------------------------------------------
Simulated Test of SCJP for JAVA2 PlatFORM
(only for training)
1. 1) public class ReturnIt{
2) returnType methodA(byte x,do
uble y){
3) return (short)x/y*2;
4) }
5) }
what is valid returnType for methodA in line 2?
2. 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. publicdo
uble getNum(float d){return 4.0d;}
3. public class IfTest{
public static void main(String args[]){
int x=3;
int y=1;
if(x=y)
System.out.println("Not equal");
else
System.out.println("Equal");
}
}
what is the result?
4. public class Foo{
public static void main(String args[]){
try{return;}
finally{ System.out.println("Finally");}
}
}
what is the result?
A. print out nothing
B. print out "Finally"
C. compile error
5. public class Test{
public static String output="";
public static void foo(int i){
try {
if(i==1){
throw new Exception();
}
output +="1";
}
catch(Exception e){
output+="2";
return;
}
finally{
output+="3";
}
output+="4";
}
public static void main(String args[]){
foo(0);
foo(1);
24)
}
}
what is the value of output at line 24?
6. public class Ifelse
{
public static void main(String args[]){
if(odd(5))
System.out.println("odd");
else
System.out.println("even");
}
public static int odd(int x){return x%2;}
}
what is output?
7. class ExceptionTest{
public static void main(String args[]){
try{
methodA();
}catch(IOException e){
System.out.println("caught IOException");
}catch(Exception e){
System.out.println("caught Exception");
}
}
}
If methodA() throws a IOException, what is the result?
8. int i=1,j=10;
do
{
if(i++>--j) continue;
}while(i<5);
After Execution, what are the value for i and j?
A. i=6 j=5
B. B.i=5 j=5
C. i=6 j=4
D. i=5 j=6
E. i=6 j=6
9. 1)public class X{
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) oa[0]=null;
8) System.out.println(oa[0]);
9) }
10) }
which line is the earliest point the object a refered is definitely elibile to be garbage collectioned?
A.After line 4 B. After line 5 C.After line 6
D.After line 7 E.After line 9(that is,as the method returns)
10. 1) interface Foo{
2) int k=0;
3) }
4) public class Test implements Foo{
5) public static void main(String args[]){
6) int i;
7) Test test =new Test();
8) i=test.k;
9) i=Test.k;
10) i=Foo.k;
11) }
12) }
what is the result?
11. what is reserved words in java?
A. run
B. default
C. implement
D. import
12. public class Test{
public static void main(String[] args){
String foo=args[1];
Sring bar=args[2];
String baz=args[3];
}
}
java Test Red Green Blue
what is the value of baz?
A. baz has value of ""
B. baz has value of null
C. baz has value of "Red"
D. baz has value of "Blue"
E. baz has value of "Green"
F. the codedo
es not compile
G. the program throw an exception
13. int index=1;
int foo[]=new int[3];
int bar=foo[index];
int baz=bar+index;
what is the result?
A. baz has a value of 0
B. baz has value of 1
C. baz has value of 2
D. an exception is thrown
E. the code will not compile
14. which three are valid declaraction of a float?
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;
15. public class Foo{
public static void main(String args[]){
String s;
System.out.println("s="+s);
}
}
what is the result?
16. 1) public class Test{
2) public static void main(String args[]){
3) int i=oxFFFFFFF1;
4) int j=~i;
5)
6) }
7) }
which is decimal value of j at line 5?
A. 0 B.1 C.14 D.-15 E. compile error at line 3
F. compile error at line 4
17. float f=4.2F;
Float g=new Float(4.2F);
do
uble d=newdo
uble(4.2);
Which are true?
A. f==g B. g==g C. d==f D. d.equals(f) E d.equals(g) F. g.equals(4.2);
18. public class Test{
public static void add3(Integer i){
3) int val=i.intvalue();
val+=3;
i=new Integer(val);
}
public static void main(String args[]){
Integer i=new Integer(0);
add3(i);
System.out.println(i.intvalue());
}
}
what is the result?
A. compile fail B.print out "0" C.print out "3"
D.compile succeded but exception at line 3
19. public class Test{
public static void main(String[] args){
System.out.println(6^3);
}
}
what is output?
20. public class Test{
public static void stringReplace(String text){
text=text.replace('j','l');
}
public static void bufferReplace(StringBuffer text){
text=text.append("c");
}
public static void main(String args[]){
String textString=new String("java");
StringBuffer textBuffer=new StringBuffer("java");
StringReplace(textString);
bufferReplace(textBuffer);
System.out.println(textString+textBuffer);
}
}
what is the output?
21. public class ConstOver{
public ConstOver(int x, int y, int z){}
}
which two overload the ConstOver constructor?
A.ConstOver(){}
B.protected int ConstOver(){}
C.private ConstOver(int z, int y, byte x){}
D.public void ConstOver(byte x, byte y, byte z){}
E.public Object ConstOver(int x, int y, int z){}
22. public class MethodOver{
public void setVar(int a, int b, float c){}
}
which overload the setVar?
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, float c){return a;}
23. class EnclosingOne{
public class InsideOne{}
}
public class InnerTest{
public static void main(String args[]){
EnclosingOne eo=new EnclosingOne();
//insert code here
}
}
A.InsideOne ei=eo.new InsideOne();
B.eo.InsideOne ei=eo.new InsideOne();
C.InsideOne ei=EnclosingOne.new InsideOne();
D.InsideOne ei=eo.new InsideOne();
E.EnclosingOne.InsideOne ei=eo.new InsideOne();
24. What is "is a" relation?
A.public interface Color{}
public class Shape{private Color color;}
B.interface Component{}
class Container implements Component{
private Component[] children;
}
C.public class Species{}
public class Animal{private Species species;}
25. 1)package foo;
2)
3)public class Outer{
4)public static class Inner{
5)}
6)}
which is true to instantiated Inner class inside Outer?
A. new Outer.Inner()
B. new Inner()
26. class BaseClass{
private float x=1.0f;
private float getVar(){return x;}
}
class SubClass extends BaseClass{
private float x=2.0f;
//insert code
}
what are true to override getVar()?
A.float getVar(){
B.public float getVar(){
C.publicdo
uble getVar(){
D.protected float getVar(){
E.public float getVar(float f){
27. public class SychTest{
private int x;
private int y;
public void setX(int i){ x=i;}
public void setY(int i){y=i;}
public Synchronized void setXY(int i){
setX(i);
setY(i);
}
public Synchronized boolean check(){
return x!=y;
}
}
Under which conditions will check() return true when called from a different class?
A.check() can never return true.
B.check() can return true when setXY is callled by multiple threads.
C.check() can return true when multiple threads call setX and setY separately.
D.check() can only return true if SychTest is changed allow x and y to be set separately.
28. 1)public class X implements Runnable{
2)private int x;
3)private int y;
4)public static void main(String[] args){
5) X that =new X();
6) (new Thread(that)).start();
7) (new Thread(that)).start();
8) }
9) public synchronized void run(){
10) for(;
{
11) x++;
12) Y++;
13) System.out.println("x="+x+",y="+y);
14) }
15) }
16) }
what is the result?
A.compile error at line 6
B.the program prints pairs of values for x and y that are
always the same on the same time
29. class A implements Runnable{
int i;
public void run(){
try{
Thread.sleep(5000);
i=10;
}catch(InterruptException e){}
}
}
public static void main(String[] args){
try{
A a=new A();
Thread t=new Thread(a);
t.start();
17)
int j=a.i;
19)
}catch(Exception e){}
}
}
what be added at line line 17, ensure j=10 at line 19?
A. a.wait();
B. t.wait();
C. t.join();
D.t.yield();
E.t.notify();
F. a.notify();
G.t.interrupt();
30. Given an ActionEvent, how to indentify the affected component?
A.getTarget();
B.getClass();
C.getSource();
D.getActionCommand();
31. import java.awt.*;
public class X extends Frame{
public static void main(String[] args){
X x=new X();
x.pack();
x.setVisible(true);}
public X(){
setLayout(new GridLayout(2,2));
Panel p1=new Panel();
add(p1);
Button b1=new Button("One");
p1.add(b1);
Panel p2=new Panel();
add(p2);
Button b2=new Button("Two");
p2.add(b2);
Button b3=new Button("Three");
p2.add(b3);
Button b4=new Button("Four");
add(b4);
}
}
when the frame is resized,
A.all change height B.all change width C.Button "One" change height
D.Button "Two" change height E.Button "Three" change width
F.Button "Four" change height and width
32. 1)public class X{
2) public static void main(String[] args){
3) String foo="ABCDE";
4) foo.substring(3);
5) foo.concat("XYZ");
6) }
7) }
what is the value of foo at line 6?
33. How to calculate cosine 42 degree?
A.double d=Math.cos(42);
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.toRadious(42);
34. public class Test{
public static void main(String[] args){
StringBuffer a=new StringBufer("A");
StringBuffer b=new StringBufer("B");
operate(a,b);
System.out.pintln(a+","+b);
}
public static void operate(StringBuffer x, StringBuffer y){
x.append
;
y=x;
}
}
what is the output?
35. 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(foo.i);
9) }
10) }
what is result?
A.compile error at line 6
B.compile error at line 7
C.print out 3
36. public class FooBar{
public static void main(String[] args){
int i=0,j=5;
4) tp: for(;;i++){
for(;;--j)
if(i>j)break tp;
}
System.out.println("i="+i+",j="+j);
}
}
what is the result?
A.i=1,j=-1 B. i=0,j=-1 C.i=1,j=4 D.i=0,j=4
E.compile error at line 4
37. public class Foo{
public static void main(String[] args){
try{System.exit(0);}
finally{System.out.println("Finally");}
}
}
what is the result?
A.print out nothing
B.print out "Finally"
38. which four types of objects can be thrown use "throws"?
A.Error
B.Event
C.Object
D.Excption
E.Throwable
F.RuntimeException
39. 1)public class Test{
2) public static void main(String[] args){
3) unsigned byte b=0;
4) b--;
5)
6) }
7) }
what is the value of b at line 5?
A.-1 B.255 C.127 D.compile fail E.compile succeeded but run error
40. public class ExceptionTest{
class TestException extends Exception{}
public void runTest() throws TestException{}
public void test() /* point x */ {
runTest();
}
}
At point x, which code can be add on to make the code compile?
A.throws Exception B.catch (Exception e)
41. String foo="blue";
boolean[] bar=new boolean[1];
if(bar[0]){
foo="green";
}
what is the value of foo?
A."" B.null C.blue D.green
42. public class X{
public static void main(String args[]){
Object o1=new Object();
Object o2=o1;
if(o1.equals(o2)){
System.out.prinln("Equal");
}
}
}
what is result?
43. which two are equivalent?
A. 3/2
B. 3<2
C. 3*4
D. 3<<2
E. 3*2^2
F. 3<<<2
44. int index=1;
String[] test=new String[3];
String foo=test[index];
what is the result of foo?
A. "" B.null C.throw a Exception D.not compile
45. public class Test{
static void leftshift(int i, int j){
i<<=j;
}
public static void main(String args[]){
int i=4, j=2;
leftshift(i,j);
System.out.println(i);
}
}
what is the result?
46. public class X{
private static int a;
public static void main(String[] args){
modify(a);
System.out.println(a);
}
public static void modify(int a){
a++;
}
}
what is the result?
47. public class Test{
private static int j=0;
public static boolean methodB(int k){
j+=k;
return true;
}
public static void methodA(int i){
boolean b;
b=i>10&methodB(1);
b=i>10&&methodB(2);
}
public static void main(String args){
methodA(0);
17)
}
}
what is the value of j at line 17?
48. class A{
public String toString(){
return "4";
}
}
class B extends A{
public String toString(){
return super.toString()+"3";
}
}
public class Test{
public static void main(String args){
B b=new B();
System.out.println(b.toString());
}
}
what is the result?
49. class A implements Runnable{
public int i=1;
public void run(){
this.i=10;
}
}
public class Test{
public static void main(String args){
A a=new A();
11) new Thread(a).start();
int j=a.i;
13)
}
}
what is the value of j at line 13?
A. 1
B. 10
C. the value of j cannot be determined
D. An error at line 11 cause compilation to fail
50. public class SyncTest{
public static void main(String[] args){
final StringBuffer s1=new StirngBuffer();
final StringBuffer s2=new StirngBuffer();
new Thread(){
public void run(){
Synchronized(s1){
s1.append("A");
Synchronized(s2){
s2.append("B");
System.out.print(s1);
System.out.print(s2);
}
}
}
}.start();
new Thread(){
public void run(){
Synchronized(s2){
s2.append("C");
Synchronized(s1){
s1.append("D");
System.out.print(s2);
System.out.print(s1);
}
}
}
}.start();
}
}
what is the result?
A.the result depends on different system and different thread model
B.the result cannot be determined
51. public class Test{
public static void main(String[] args){
String foo="blue";
String bar=foo;
foo="green";
System.out.println(bar);
}
}
what is the result?
52. which interface Hashtable implements?
A. java.util.Map
B. java.util.List
C. java.util.Hashable
D. java.util.Collection
53. which two are true?
A. static inner class requires a static initializer
B. A static inner class requires an instance of the enclosing class
C. A static inner class has no reference to an instance of the enclosing class
D. A static inner class has accesss to the non-static member of the other class
E. static members of a static inner class can be referenced using the class
name of the static inner class
54. which two are true?
A. An anonymous inner class can be declared inside of a method
B. An anonymous inner class constructor can take arguments in some situations
C. An anonymous inner class that is a direct subclass of Object can implements
multiple interface
D. Even if a class Superdo
es not implement any interfaces, it is still possible
to define an anonymous inner class that is an immediate subclass of Super that
implements a single interface
E. Even if a class Superdo
es not implement any interfaces, it is still possible
to define an anonymous inner class that is an immediate subclass of Super that
implements multipe interface
55. class A{
public int getNumber(int a){
return a+1;
}
}
class B extends A{
8) public int getNumber(int a, char c){
return a+2;
}
public static void main(String[] args){
B b=new B();
14) System.out.println(b.getNumber(0));
}
}
what is the result?
A. compilation succeeds and 1 is printed
B. compilation succeeds and 2 is printed
C. An error at line 8 cause compilation to fail
D. An error at line 14 cause compilation to fail
56. import java.awt.*;
public class X extends Frame{
public static void main(String[] args){
X x=new X();
x.pack();
x.setVisible(true);
}
public X(){
setLayout(new BorderLayout());
Panel p=new Panel();
add(p,BorderLayout.NORTH);
Button b=new Button("North");
p.add(b);
Button b1=new Button("South");
add(b1,BorderLayout.SOUTH);
}
which two are true?
A. The button labeled "North" and "South" will have the same width
B. The button labeled "North" and "South" will have the same height
C. The height of the button labeled "North" can vary if the Frame is resized
D. The height of the button labeled "South" can vary if the Frame is resized
E. The width of the button labeled "North" is constant even if the Frame is resized
F. The width of the button labeled "South" is constant even if the Frame is resized
57. which two interfaces provide the capability to store objects using a key-value pair?
A. java.util.Map
B. java.util.Set
C. java.util.List
D. java.util.SortedSet
E. java.util.SortedMap
F. java.util.Collection
58. which two declaretions prevent the overriding of a method?
A. final void methoda(){}
B. void final methoda(){}
C. static void methoda(){}
D. static final void methoda(){}
E. final abstract void methoda(){}
59. which two are true?
public class OuterClass{
privatedo
uble d1=1.0;
//inser code here
}
A. static class InnerOne{
publicdo
uble methoda(){return d1;}
B. static class InnerOne{
staticdo
uble methoda(){return d1;}
C. private class InnerOne{
publicdo
uble methoda(){return d1;}
D. protected class InnerOne{
staticdo
uble methoda(){return d1;}
E. public abstract class InnerOne{
public abstractdo
uble methoda();
60. You want a class to have access to members of another class in the same
package which is the most restrictive access modifier that will accomplish
this objective?
A. public
B. private
C. protected
D. transient
E. No acess modifier is required
61. which two statements declare an array capable of 10 ints?
A. int[] foo;
B. int foo[];
C. int foo[10];
D. Object[] foo;
E. Object foo[10];
62. public class SwitchTest{
public static void main(String[] args){
3) System.out.println("value="+switchIt(4));
}
public static int switchIt(int x){
int j=1;
switch(x){
case 1: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
default: j++;
}
return j+x;
}
}
what is the output from line 3?
A. value=3 B. value=4 C. value=5 D. value=6 E. value=7 F. value=8
63. which will declare a method that is available to all members of the same
package and can be referenced without an instance of the class?
A. abstract public void methoda();
B. public abstractdo
uble methoda();
C. static void methoda(double d1){}
D. public nativedo
uble methoda(){}
E. protected void methoda(double d1){}
64. 1)public class SuperClass{
2) class SubClassA extends SuperClass{}
3) class SubClassB extends SuperClass{}
4) public void test(SubClassA foo){
5) SuperClass bar=foo;
6) }
7) }
which statement is true about the assignment in line 5?
A. The assignment in line 5 is illegal
B. The assignment in line 5 is legal, but throw a ClassCastException
C. legal and will always executes without throw an Exception
65. which two are true to describe an entire encapsulation class?
A. member data have no access modifiers
B. member data can be modified directly
C. the access modifier for methods is protected
D. the access modifier to member data is private
E. methods provide for access and modification of data
66. public class X implements Runnable{
public static void main(String[] args){
3) //insert code
}
public void run(){
int x=0,y=0;
for(;
{
x++;
Y++;
System.out.println("x="+x+",y="+y);
}
}
}
which codes are added to line 3 to cause run() to be executed?
A. X x=new X();
x.run();
B. X x=new X();
new Thread(x).run();
C. X x=new X();
new Thread(x).start();
D. Thread t=new Thread(x).run();
E. Thread t=new Thread(x).start();
67. which gets the name of the parent directory of file "file.txt"?
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. Diretory dir=(new File("file.txt")).getParentDir();
String name=dir.getName();
68. The file "file.txt" exists on the file system and contains ASCII text.
try{
File f=new File("file.txt");
OutputStream out=new FileOutputStream(f);
}catch (IOException e){}
A. the codedo
es 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
69. class Super{
public int i=0;
public Super(String text){
i=1;
}
}
public class Sub extends Super{
public Sub(String text){
i=2;
}
public static void main(String args[]){
Sub sub=new Sub("Hello");
System.out.println(sub.i);
}
}
what is the result?
A. compile will fail
B. compile success and print "0"
C. compile success and print "1"
D. compile success and print "2"
70. import java.io.IOException;
public class ExceptionTest{
public static void main(String args[]){
try{
methodA();
}catch(IOException e){
System.out.println("Caught Exception");
}
}
public void methodA(){
throw new IOException();
}
}
what is the result?
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
71. You are assigned the task of building a Panel containing a TextArea at
the top, a Labbel directly bellow it, and a Button directly bellow the
Label. If the three components 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
C.FlowLayout
D.BorderLayout
E.GridbagLayout
72. You need to store elements in a collection that guarantees that no duplicates
are stored and all elements can be access in nature order, which interace
provides that capability?
A. java.uil.Map
B.java.util.Set
C.java.util.List
D.java.util.SortedSet
E.java.util.SortedMap
F.java.util.Collection
73. which two cannot directly cause a thread to stop executing?
A.calling the yield method
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
74. 1)public class Foo implements Runnable{
2) public void run(Thread t){
System.out.println("Running");
}
public static void main(String[] args){
new Thread(new Foo()).start();
}
}
what is the result?
A.An Exception is thrown
B.The program exits without printing anything
C.An error at line 1 causes complication to fail
D.An error at line 2 causes complication to fail
E."Running" is pinted and the program exits
75. which method in the Thread class is used to create and launch a new thread of execution?
A.run() B.start() C. begin
() D.run(Runnable r) E.execute(Thread t)
76. which is true?
A.If only one thread is blocked in the wait method of an object, and another
thread executes the notify method on that same object,then
the first thread
immediately resumes executes.
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 thread that executed
the wait call first definitely resumes execution as a direct and sole consequence
of the notify call
77. 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 mutiple 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 encloing outer class
78. public class X{
public Object m(){
3)Object o=new Float(3.14f);
Object[] oa=new Object[1];
Oa[0]=0;
o=null;
return oa[0];
}
}
when is the float Object, created in line 3 ,collected as garbage?
A.just after line 5 B.just after line 6 C.just after line 7 D.never in this method
79. which will declare a method that forces a subclass to implement?
A.publicdo
uble methoda()
B.abstract public void methoda()
80. //point X
public class Foo{
public static void main(String[] args){
PrintWriter out=new PrintWriter(new java.i
utputStreamWriter(System.out),true);
out.println("Hello");
}
}
which statement at point X on line 1 allows this code to compile and run?
A.import java.io.PrintWriter B.include java.io.PrintWriter
C.import java.i
utputStreamWriter D.include java.i
utputStreamWriter
E.No statement is needed
81. which prevent create a subclass of outer class?
A.static class FooBar{}
B.pivate class Foobar{}
C.abstract class FooBar{}
D.final public class FooBar{}
E.final abstract class FooBar{}
82. 1)abstract class AbstractIt{
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?
83. byte[] array1,array2[]
byte array3[][]
byte[][] array4
if each has been initialized, which statement will cause a compile error?
A.array2=array1 B.array2=array3 C.array2=array4
84. what writes the text "" to the end of the file "file.txt"?
A.OutputStream out=new FileOutputStream("file.txt");
out.writeBytes("/n");
B.OutputStream os=new FileOutputStream("file.txt",true);
DataOutputStream out=new DataOutputStream(os);
out.writeBytes("/n");
C.OutputStream os=new FileOutputStream("file.txt");
DataOutputStream out=new DataOutputStream(os);
out.writeBytes("/n");
D.OutputStream os=new OutputStream("file.txt",true);
DataOutputStream out=new DataOutputStream(os);
out.writeBytes("/n");
85. which constructs a DataOutputStream ?
A.new DataOutputStream("out.txt");
B.new DataOutputStream(new File("out.txt"));
C.new DataOutputStream(new Writer("out.txt"));
D.new DataOutputStream(new OutputStream("out.txt"));
E.new DataOutputStream(new FileWriter("out.txt"));
F.new DataOutputStream(new FileOutputSream("out.txt"));
86. which statement is true for the class java.util.HashSet?
A.The elements in the collection are ordered
B.The collection is guaranteeded to be immutable
C.The elements in the collection are guaranteeded to be unique
D.The elements in the collection are access using a unique key
E.The elements in the collection are guaranteed to be synchronized
87. 1) public abstract class Test{
2) public abstract void methodA();
3) public abstract void methodB()
4) { System.out.println("Hello");
5) }
6) }
which three changes(made independently) allow the code to compile?
A.add a method body to methodA.
B.replace line 4-5 with a ";".
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 entirety and change class to interface in line 1.
88. ClassOne.java
package com.ab.pkg1;
public class ClassOne{
private char var='a';
char getVar(){ return var;}
}
ClassTest.java
package com.ab.pkg2;
import com.ab.pkg1.ClassOne;
public class ClassTest extends ClassOne{
public static void main(String args[]){
char a=new ClassOne().getVar();
char b=new ClassTest().getVar();
}
}
what is the result?
89. int i=1,j=10;
do
{
if(i>j)continue;
j--;
}while(++i<6);
what are the vale of i and j?
A.i=6,j=5
B.i=5,j=5
C.i=6,j=4
D.i=5,j=6
E.i=6,j=6
90. public class Foo{
public static void main(String[] args){
int i=1;
int j=i++;
if((i>++j)&&(i++==j)){
i+=j;
}
}
}
what is the final value i and j?
91. which two are equivalent?
A.16>4
B.16/2
C.16*4
D.16>>2
E.16/2^2
F.16>>>2
92. public class X{
public static void main(String[] args){
byte b=127;
4) byte c=126;
5) byte d=b+c;
}
}
A.Line 5 throws an exception indicating "out of range"
B.Line 5 cause a compile fail
C.compile succeeded
93. AnInterface is an interface
AnAdapter0 is a non-abstract,non-final class with a zero
argument constructer
AnAdapter1 is a non-abstract,non-final class without a zero
argument constructer,but with a constructer that takes one int argument
which two creat an anoymous inner class?
A.AnAdapter0 aa=new AnAdapter0(){}
B.AnAdapter1 aa=new AnAdapter1(5){}
C.AnAdapter1 aa=new AnAdapter1(){}
D.AnAdapter0 aa=new AnAdapter0(5){}
E.AnInterface ai=new AnInterface(5){}
94. which two creat an InputStream and open the file"file.txt"
for reading?
A.InputStream in=new FileInputStream("file.txt");
B.FileInputStream in=new FileInputStream(new File("file.txt"));
C.InputStream in=new FileReader("file.txt");
95. which constructs a BuferedInputStream?
A.new BufferedInputStream(new FileInputStream("in.txt"));
B.new BufferedInputStream(new FileReader("in.txt"));
96. which can be used to encode char s for output?
A.java.i
utputStreamWriter
B.java.io.FileOutputStream
C.java.io.DataOutputStream
97. which determines if "prefs" is a directory and exist on the file system?
A.boolean exists=(new File("prefs")).isDirectory();
B.boolean exists=(new File("prefs")).isDir();
98.which code determines the int value foo closest to, but not greater than, ado
uble 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);
99. import java.awt.*;
public class Test extends Frame{
public Test(){
add(new Label("Hello"));
add(new TextField("Hello"));
add(new Button("Hello"));
pack();
show();}
public static void main(String[] args){
new Test();
}
}
what is the result?
100. which is true?
A. Any statement that may throw an Exception must be enclosed in a try block.
B. Any statement that may throw an Error must be enclosed in a try block.
C. Any statement that may throw an RuntimeException must be enclosed in a try block.
D.No exception are subclass of Error.
101. which one is true?
A.An anonymous class can be declared as static.
B.A static inner class cannot be a static member of the outer class.
C.A static inner classdo
es require an instance of the enclosing class.
D.Instance member of a static inner class can be referened using the class name of the
static inner class.
102.public class MyCircle{
publicdo
uble radius;
publicdo
uble diameter;
public void setRadius(double radious){
6) this.radius=radius;
7) this.diameter=radius*2;}
publicdo
uble getRadius(){
return radius;}
}
A. The MyCircle class is fullly encapsulated
B. The diameter of a given MyCircle is guaranteed to be twice its radius.
C. Line 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.
103.Given:
public class ArrayList{
public static void main(String[] args){
float f1[],f2[];
f1=new float[10];
f2=f1;
System.out.println("f2[0]="+f2[0]);
}
}
what is the result?
104.public class X{
public static void main(String[] args){
int[] a=new int[1];
4) modify(a);
System.out.println(a[0]);
}
public static void modify(int[] a){
9) a[0]++;}
}
what is the result?
A.The program runs and prints "0";
B.The program runs and prints "1";
C.The program runs but aborts with an exception;
D.An error "possible undefined variable" at line 4 cause compilation to fail;
E.An error "possible undefined variable" at line 9 cause compilation to fail;
answer:
doble
b
compile error
b
13423
compile error
caught IOException
d
d
编译成功,正确运行
b,d
g
b
a,d,f
compile error
c
b(e在语法上正确)
b
5
javajavac
a,c
a,c,d
e
b
b(如在外部,用A)
a,b,d
c
b
c
c
F
abcde
c
ab,b
c
b
a
adef
d
a
c
Equal
c,d
b
4
0
1
43
c
a,b
blue
a
c,e
a,d
a
b,e
a,e
a,d
c,e
e
a,b
f
c
c
d,e
c
b
c
a
a
e
d
a,e
d
b
b
d
d(单选为D,多选为C,D)
b
a
d
compile error
a
b
f
c
b,d,f
compile error
a
i=2,j=2
d,f
b
a,b
a,b
a
a
a
e
覆盖,框架出现,只包含按钮
d
c
d
f2[0]=0.0
b