这是在CU的精华中抄下来的,放在这里,有时间自己做做!
一. 真实考试说明
1.考试形式:网络计算机
2.考题形式:多选,单选,简答
3.题量:60
4.考试时间:120分钟
5.更新考试记忆或其它认证知识请登陆
6.本模拟题相对经典陈旧,是北京网畅创总裁胡德平1997SCJP模拟版本地扩充
二.模拟题
1.Which statement about the garbage collection mechanism are true?
A.Garbage collection require additional program code in cases where multiple threads are running.
B.The programmer can indicate that a reference through a local variable is no longer of interest.
C.The programmer has a mechanism that explicit and immediately frees the memory used by Java objects.
D.The garbage collection mechanism can free the memory used by Java Object at expectable time.
E.The garbage collection system never reclaims memory from objects while are still accessible to running user threads.
2. Give the following method:
1)public void method( ){
2) String a,b;
3) a=new String(“hello world”);
4) b=new String(“game over”);
5) System.out.println(a+b+”ok”);
6) a=null;
7) a=b;
System.out.println(a);
9) }
In the absence of compiler optimization, which is the earliest point the object a referred is definitely hand to be garbage collection.
A. before line 3 B.before line 5 C. before line 6 D.before line 7 E. Before line 9
3. Which statement about listener is true?
A.Most component allow multiple listeners to be added.
B.If multiple listener be add to a single component, the event only affected one listener.
C.Component don’t allow multiple listeners to be add.
D.The listener mechanism allows you to call an addXXXListener method as many times as is needed, specifying as many different listeners as your design require.
4.Give the following code:
public class Example{
public static void main(String args[] ){
int l=0;
do{
System.out.println(“Doing it for l is:”+l);
}while(--l>;0)
System.out.println(“Finish”);
}
}
Which well be output:
A. Doing it for l is 3B. Doing it for l is 1C. Doing it for l is 2
D. Doing it for l is 0E. Doing it for l is –1F. Finish
5. Give the code fragment:
1)switch(x){
2) case 1: System.out.println(“Test 1”);break;
3) case 2:
4) case 3: System.out.println(“Test 2”);break;
5) default: System.out.println(“end”);
6) }
which value of x would cause “Test 2” to the output:
A. 1B. 2C. 3D. default
6. Give incompleted method:
1)
2){if(unsafe()){//do something…}
3)else if(safe()){//do the other…}
4)}
The method unsafe() will throw an IOException, which completes the method of declaration when added at line one?
A.public IOException methodName()
B.public void methodName()
C.public void methodName() throw IOException
D.public void methodName() throws IOException
E.public void methodName() throws Exception
7. Give the code fragment:
if(x>;4){
System.out.println(“Test 1”);}
else if (x>;9){
System.out.println(“Test 2”);}
else {
System.out.println(“Test 3”);}
Which range of value x would produce of output “Test 2”?
A. x<4B. x>;4C. x>;9D. None
8. Give the following method:
public void example(){
try{
unsafe();
System.out.println(“Test1”);
}catch(SafeException e){System.out.println(“Test 2”);
}finally{System.out.println(“Test 3”);}
System.out.println(“Test 4”);
Which will display if method unsafe () run normally?
A. Test 1B. Test 2C. Test 3D. Test 4
9. Which method you define as the starting point of new thread in a class from which new the thread can be execution?
A. public void start()B. public void run()C. public void int()
D. public static void main(String args[])E. public void runnable()
10.Given the following class definition:
class A{
protected int i;
A(int i){
this.i=i;
}
}
which of the following would be a valid inner class for this class?
Select all valid answers:
A. class B{
}
B.class B extends A{
}
C.class B extends A{
B(){System.out.println(“i=”+i);}
}
D.class B{
class A{}
}
E.class A{}
11. Which modifier should be applied to a method for the lock of object this to be obtained prior to execution any of the method body?
A. synchronizedB. abstractC. finalD. staticE. public
12. The following code is entire contents of a file called Example.java,causes precisely one error during compilation:
1)class SubClass extends BaseClass{
2) }
3)class BaseClass(){
4) String str;
5) public BaseClass(){
6) System.out.println(“ok”);}
7) public BaseClass(String s){
str=s;}
9)}
10)public class Example{
11) public void method(){
12) SubClass s=new SubClass(“hello”);
13) BaseClass b=new BaseClass(“world”);
14) }
15) }
Which line would be cause the error?
A. 9B. 10C. 11D.12
13. Which statement is correctly declare a variable a which is suitable for refering to an array of 50 string empty object?
A. String [] aB. String a[]C. char a[][]D. String a[50]F. Object a[50]
14. Give the following java source fragment:
//point x
public class Interesting{
//do something
}
Which statement is correctly Java syntax at point x?
A. import java.awt.*;B.package mypackage;C. static int PI=3.14
D. public class MyClass{//do other thing…}E. class MyClass{//do something…}
15. Give this class outline:
class Example{
private int x;
//rest of class body…
}
Assuming that x invoked by the code java Example, which statement can made x be directly accessible in main() method of Example.java?
A. change private int x to public int xB. change private int x to static int x
C. change private int x to protected int xD. change private int x to final int x
16. A class design requires that a member variable should be accessible only by same package, which modifier word should be used?
A. protectedB. publicC. no modifierD. private
17. Which modifier should be applied to a declaration of a class member variable for the value of variable to remain constant after the creation of the object?
18. Which is corrected argument of main() method of application?
A. String argsB. String ar[]C. Char args[][]D. StringBuffer arg[]
19. “The Employee object is a Person, An Employee has appointment store in a vector, a hire date and a number of dependent”
short answer: use shortest statement declare a class of Employee.
20. Give the following class definition inseparate source files:
public class Example{
public Example(){//do something}
protected Example(int i){//do something}
protected void method(){//do something}
}
public class Hello extends Example{//member method and member variable}
Which methods are corrected added to the class Hello?
A. public void Example(){}B. public void method(){}
C. protected void method(){}D. private void method(){}
21. Float s=new Float(0.9F);
Float t=new Float(0.9F);
Double u=new Double(0.9);
Which expression’s result is true?
A. s= =tB. s.equals(t)C. s= =uD. t.equals(u)
22. Give following class:
class AClass{
private long val;
public AClass(long v){val=v;}
public static void main(String args[]){
AClass x=new AClass(10L);
AClass y=new AClass(10L);
AClass z=y;
long a=10L;
int b=10;
}
}
Which expression result is true?
A. a= =b;B. a= =x;C. y= =z;D. x= =y;
E. a= =10.0;
23. String s=”Example String”;
Which operation is legal?
A. s>;>;>;=3;B. int i=s.length();C. s[3]=“x”;
D. String short_s=s.trim();E. String t=“root”+s;
24. What happens when you try to compile and run the following program?
class Mystery{
String s;
public static void main(String[] args){
Mystery m=new Mystery();
m.go();
}
void Mystery(){
s=”constructor”;
}
void go(){
System.out.println(s);
}
}
A.this code will not compile
B.this code compile but throws an exception at runtime
C.this code runs but nothing appears in the standard output
D.this code runs and “constructor” in the standard output
E.this code runs and writes ”null” in the standard output
25. What use to position a Button in a Frame ,only width of Button is affected by the Frame size, which Layout Button well be set ?
A. FlowLayout;B. GridLayout;C. North of BorderLayout
D. South of BorderLayoutE. East or West of BorderLayout
26. What use to position a Button in a Frame, size of Button is not affected by the Frame size, which Layout Button will be set?
A. FlowLayout;B. GridLayout;C. North of BorderLayout
D. South of BorderLayoutE. East or West of BorderLayout
27. Select valid identifier of Java:
A. userNameB. %passwdC. 3d_gameD. $chargeE. this
28. Which are Java keyword?
A. gotoB. nullC. FALSED. nativeE. const
29. Give the following java class:
public class Example{
static int x[]=new int[15];
public static void main(String args[]){
System.out.println(x[5]);
}
}
Which statement is corrected?
A.When compile, some error will occur.
B.When run, some error will occur.
C.Output is zero.
D.Output is null.
30. Give the following java class:
public class Example{
public static void main(String args[]){
static int x[] = new int[15];
System.out.println(x[5]);
}
}
Which statement is corrected?
A.When compile, some error will occur.
B.When run, some error will occur.
C.Output is zero.
D.Output is null.
31. Short answer:
The decimal value of i is 12, the octal i value is:
32. Short answer:
The decimal value of i is 7, the hexadecimal i value is:
33. Give the following class:
public class Example{
String str=new String(“good”);
char ch[]={‘a’,’b’,’c’};
public static void main(String args[]){
Example ex=new Example();
ex.change(ex.str,ex.ch);
System.out.println(ex.str+”and”+ex.ch[0] +ex.ch[1] +ex.ch[2]);
}
public void change(String str,char ch[]){
str=”test ok”;ch[0]=’g’;
}
}
Which is the output:
A. good and abcB. good and gbcC. test ok and abcD. test ok and gbc
34. Which code fragments would correctly identify the number of arguments passed via command line to a Java application, exclude the name of the class that is being invoke.
A. int count = args.length;B. int count = args.length-1;
C. int count=0; while(args[count]!=null)
count++;
D. int count=0;while
(!(args[count].equals(“”))) count++;
35. FilterOutputStream is the parent class for BufferedOutputStream, DataOutputStream and PrintStream. Which classes are valid argument for the constructor of a FilterOutputStream?
A. InputStreamB. OutputStreamC. File
D. RandomAccessFile E. StreamTokenizer
36. Given this skeleton of a class currently under construction:
public class Example{
int x,y,z;
public Example (int a, int b) {
//lots of complex computation
x=a; y=b;
}
public Example(int a, int b, int c){
// do everything the same as single argument
// version of constructor
// including assignment x=a, y=b, z=c
z=c;
}
}
What is the most concise way to code the “do everything…” part of the constructor taking two arguments?
Short answer:
37. Which correctly create a two dimensional array of integers?
A.int a[][] = new int[][];
B.int a[10][10] = new int[][];
C.int a[][] = new int[10][10];
D.int [][]a = new int[10][10];
E.int []a[] = new int[10][10];
38. Which are correct class declarations? Assume in each case that the text constitutes the entire contents of a file called Fred.java?
A.public class Fred{
public int x = 0;
public Fred (int x){
this.x=x;
}
}
B.public class fred{
public int x = 0;
public Fred (int x){
this.x=x;
}
}
C.public class Fred extends MyBaseClass, MyOtherBaseClass{
public int x = 0;
public Fred(int xval){
x=xval;
}
}
D.protected class Fred{
private int x = 0;
private Fred (int xval){
x=xval;
}
}
E.import java.awt.*;
public class Fred extends Object{
int x;
private Fred(int xval){
x = xval;
}
}
39. A class design requires that a particular member variable must be accessible for direct access by any subclasses of this class. but otherwise not by classes which are not members of the same package. What should be done to achieve this?
A.The variable should be marked public
B.The variable should be marked private
C.The variable should be marked protected
D.The variable should have no special access modifier
E.The variable should be marked private and an accessible method provided
40. Which correctly create an array of five empty Strings?
A.String a[] = new String[5];
for (int i=0;i<5;a[i++]=””);
B.String a []={“”,””,””,””,””};
C.String a[5];
D.String [5] a;
E.String [] a = new String[5];
for (int i = 0 ;i<5;a[i++] = null);
41. Which cannot be added to a Container?
A. an AppletB. a ComponentC. a ContainerD. a MenuComponent
E. a panel
42. Which is the return value of Event listener’s method?
A. StringB. AWTEventC. voidD. int
43. If we implements MouseListener, which is corrected argument of its method? (short answer)
44. Use the operator “>;>;” and “>;>;>;”. Which statement is true?
A.1010 0000 0000 0000 0000 0000 0000 0000 >;>; 4 give
0000 1010 0000 0000 0000 0000 0000 0000
B.1010 0000 0000 0000 0000 0000 0000 0000 >;>; 4 give
1111 1010 0000 0000 0000 0000 0000 0000
C.1010 0000 0000 0000 0000 0000 0000 0000 >;>;>; 4 give
0000 1010 0000 0000 0000 0000 0000 0000
D.1010 0000 0000 0000 0000 0000 0000 0000 >;>;>; 4 give
1111 1010 0000 0000 0000 0000 0000 0000
45. Give following fragment.
Outer: for(int i=0; i<3; i++)
inner:for(int j=0;j<3;j++){
If(j>;1)break outer;
System.out.println(j+”and”+i);
}
Which will be output?
A. 0 and 0B. 0 and 1C. 0 and 2D. 0 and 3
E. 1 and 0F. 1 and 1G. 1 and 2H. 1 and 3
I. 2 and 0J. 2 and 1K. 2 and 2L. 2 and 3
46. Examine the following code which includes an inner class:
public final class Test4 implements A{
class Inner{
void test(){
if (Test4.this.flag);{
sample();
}
}
private boolean flag=false;
}
public void sample(){
System.out.println(“Sample”);
}
public Test4(){
(new Inner()).test();
}
public static void main(String args[]){
new Test4();
}
}
What is the result:
A.Print out “Sample”
B.Program produces no output but terminates correctly.
C. Program does not terminate.
E.The program will not compile
47. What is written to the standard output given the following statement:
System.out.println(4|7);
Select the right answer:
A.4B.5C.6D.7E.0
48. Look the inheritance relation:
person
|
----------------
| |
man woman
In a source of java have the following line:
person p=new man();
What statement are corrected?
A.The expression is illegal.
B.Compile corrected but running wrong.
C.The expression is legal.
D.Will construct a person’s object.
49. Look the inheritance relation:
person
|
----------------
| |
man woman
In a source of java have the following line:
woman w=new man():
What statement are corrected?
A.The expression is illegal.
B.Compile corrected but running wrong.
C.The expression is legal.
D.Will construct a woman’s object.
50.Which can NOT be used in declaring or declaring and initializing an automatic (method local) variable?
A. finalB. static C. expressions D. Constants of non-primitive type
E.initialized arrays (such as “ {“Hello”,”Good bye”}”).
51. Given the following incomplete method:
public void method(){
1)if (someTestFails()){
2)
3) }
4)
5)}
You want to make this method throw an IOException if,and only if,the method someTestFails() returns a value of true.
Which changes achieve this?
A.Add at line 2:IOException e;
B.Add at line 4:throw e;
C.Add at line 4:throw new IOException();
D.Add at line 6:throw new IOException();
E.Modify the method declaration to indicate that an object of type Exception might be thrown.
52.Given the following definition:
String s = null;
Which code fragments cause an object of type NullPointerException to be thrown?
A. if((s!=null)&(s.length()>;0))
B. if((s!=null)&&(s.length()>;0))
C. if((s==null)|(s.length()==0))
D. if((s==null)||(s.length()==0))
53.The following is a program
1)class Exsuper{
2) String name;
3) String nick_name;
4)
5) public ExSuper(String s,String t){
6) name = s;
7) nick_name = t;
}
9)
10)public string toString(){
11) return name;
12) }
13)}
14)
15)public class Example extends ExSuper{
16)
17)public Example(String s,String t){
18) super(s,t);
19)}
20)
21)public String to String(){
22) return name +”a.k.a”+nick_name;
23)}
24)
25)public static void main(String args[]){
26) ExSuper a = new ExSuper(“First”,”1st”);
27) ExSuper b = new Example(“Second”,”2nd”);
28)
29)System.out.println(“a is”+a.toString());
30)System.out.println(“b is”+b.toString());
31) }
32)}
54.What happens when the user attempts to compile and run this program?
`A. A Compiler error occurs at line 21
B. An object of type ClassCastException is thrown at line 27
C.The following output:
a is First
b is second
D. The following output:
a is First
b is Second a.k.a 2nd
F.The following output:
a is First a.k.a 1st
b is Second a.k.a 2nd
55.Which statements are true about Listeners?
A.At most one listener can be added to any simple Component.
B.The return value from a listener is used to control the invocation of other listener
C.If multiple listeners are added to a single component, they must all be made friends to each other
D.If multiple listeners are added to single component, the order of invocation of the listener is not specified.
E.In the AWT, listener methods generally take an argument, which is an instance of some subclass of java.awt.AWTEvent class.
56.Given the following class outline:
class Example{
private int x;
// rest of class body
public static void main(String args[]){
//implementation of main mehtod}
}
Which statement is true?
A.x=2 is a valid assignment in the main() method of class Example.
B.Changing private int x to int x would make x=2 a valid assignment in the main() method of class Example.
C.Changing private int x to public int x would make x=2 a valid assignment in the main() method of class Example.
D.Changing private int x to static int x would make x=2 a valid assignment in the main() method of class Example.
E.Changing class Example to public class Example would make x=2 a valid assignment in the main() method of class Example.
57.Which statement is true about an inner class?
A.It must be anonymous
B.It can not implement an interface
C.It is only accessible in the enclosing class
D.It can access any final variables in any enclosing scope.
58.Which statement is true about the grid bag layout manager?
A.The number of rows and columns is fixed when the container is created.
B.The number of rows and columns is fixed when the GridBagLayout object is created.
C.If a component has a fill value of BOTH, then as the container change size, the component is resized.
D.Every component must carry a non-zero weightx and weighty value when it is added to the container
E.If a row has a weighty value that is non-zero, then as the container changes height, the row changes height.
59.Which statement are true about writing a class that is to handle the events issued by a user interface component.
A.Subclassing an adapter is inappropriate in this case.
B.The class should implement some listener interface
C.A class can implement multiple listener interfaces if desired.
D.A subclass of an AWT component cannot listen to its own events.
E.When implements listener interface, a class need only provide those handler methods that it chooses.
60.Which best describes the requirements of a fully encapsulated class?
A.Methods must not be private.
B.Variables must not be public.
C.The class must be marked final
D.Public methods are all marked final.
E.Modification of the objects state is only possible using method calls.
61.Which contains objects without ordering, duplication, or any particular lookup/retrieval mechanism?
A. MapB. SetC. ListD. CollectionE. Enumeration
62.What might cause the current thread to stop executing?
A.An interrupted exception is thrown.
B.The thread execute a sleep() call.
C.The thread constructs a new thread
D.A thread of higher priority becomes ready
E.The thread executes a read() call on InputStream
63.Which statements are true about threads?
A.Threads created from the same class all finish together.
B.A thread can be created only by subclassing java.lang.Thread.
C.Invoking the suspend() method stops a thread so that it cannot be restarted.
D.The Java interpreter’s natural exit occurs when no non-daemon threads remain alive.
E.Uncoordinated changes to shared data by multiple threads may result in the data being read, or left, in an inconsistent state.
64.What might FORM part of a correct inner class declaration or combined declaration and instantiation?
A.private class C
B.new SimpleInterface(){
C.new ComplexInterface(x){
D.private final abstract class(
E.new ComplexClass() implements SimpleInterface
65. Which statements are true about the garbage collection mechanisms?
A.The garbage collection mechanism release memory at pridictable times.
B.A correct program must not depend upon the timing or order of garbage collection
C.Garbage collection ensures that a program will NOT run out of memory during execution
D.The programmer can indicate that a reference through a local variable is no longer going to be used.
E.The programmer has a mechanism that explicitly and immediately frees the memory used by Java objects.
66. Given:
public class ReturnIt{
ReturnType methodA(byte x,double y){
return (short)x/y*2;
}
}
What is the valid return for methodA in line2?
A.int B. byte C. long D. short E. float F. double
67. Given:
abstract class AbstractIt{
abstract float getFloat();
}
public class AbstractTest extends AbstractIt{
private float f1 = 1.0f;
private float getFloat(){retrun f1;}
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
68.Which declaration prevents creating a subclass of an outer class?
A.static class FooBar{}
B.private class FooBar{}
C.abstract class FooBar{}
D.final public class FooBar{}
E.final abstract class FooBar{}
69.Given:
byte[] array1,array2[];
byte array3[][];
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
70.
public class Test{
public int aMethod(){
static int i=0;
i++;
return i;
}
public static void main(String args[]){
Test test = new Test();
test.aMethod();
int j=test.aMethod();
System.out.println(j);
}
}
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”.
71.You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access modifier that will accomplisher this objective?
A.public B.private C.protected D.transient E. No access modifier is qualified
72.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 ag[]){
Sub sub=new Sub(“Hello”);
System.out.println(sub.i);
}
}
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”
73. Given:
class Super{
public float getNum(){return 3.0f;}
}
public class Sub extends Super{ }
Which method , placed at line 6,will cause a complier error?
A.public float getNum(){return 4.0f;}
B.public void getNum(){}
C.public void getNum(double d){}
D.public double getNum(float d){return 4.0d;}
74. public class Test{
public static void main(String args[]){
int i=0;
while(1){
if(i==4){
break;
}
i++;
}
}
}
What is the value of i at line 10?
A.0
B.3
C.4
D.5
E.The code will not compile
75.Given:
int i=1,j=10;
do{
if(i++>;--j) continue;
}while(i<5);
After execution, what are the values for i and j?
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
76.Given:
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 the result?
A.The output is odd; B. The output is even;
C.An error on line 3 causes compilation to fail D.An error on line 8 causes compilation to fail
77.
import java.io.IOException;
public 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”);
}
}
public static 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
78.
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);
}
}
What is the value of the variable output at line 24?
Shortanswer:
79.Given:
public class Foo{
public static void main(String[] args){
try{return;}
finally{System.out.println(“Finally”);}
}
}
What is the result?
A.The program runs and prints nothing.
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.
80.Given
public class IfTest{
public static void main(String [] s){
int x=3;
int y=1;
if(x=y)
System.out.println(“Not equal”);
else
System.out.println(“Equal”);
}
}
What is the result?
A.The output is “Equal”.
B.The output is “Not equal”
C.An error at line 5 causes compilation to fail
D.The program executes but does not print a message
81.Given
public class X{
public Object m(){
Object o = new Float(3.14F);
Object [] oa = new Object[1];
oa[0] = o;
o=null;
return oa[0];
}
}
When is the Float object, created in line 3,eligible for garbage collection?
A.just after line 5
B.just after line 6
C.just after line 7(that is,as the method returns)
D.never in this method
82.Which two are reserved words in Java?(2)
A.run B. import C. default D. implement
83.Given
public class Test {
public static void main(String sg[]){
String foo=sg[1];
String bar=sg[2];
String baz=sg[3];
}
}
And 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.baz has the value of “green”
F.The code will not compile
84.Given:
int index = 1;
boolean [] test = new boolean[3];
boolean foo=test[index];
What is the result?
A.foo has the value of o.
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
85
public class Foo{
public static void main(String[] args) throws Exception{
PrintWriter out = new PrintWriter(new
java.io.OutputStreamWriter(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.io.OutputStreamwriter;
D.include java.io.OutputStreamWriter;
E.No statement is needed
86.Which three are valid declarations of a float?(3)
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;.
87.
interface Foo{
int k=0;
}
public class Test implements Foo{
public static void main(String args[]){
int i;
Test test = new Test();
i=test.k;
i=Test.k;
i=Foo.k;
}
}
A.Compilation succeeds.
B.An error at line 2 causes compilation to fail.
C.An error at line 9 causes compilation to fail.
D.An error at line 10 causes compilation to fail.
E.An error at line 11 causes compilation to fail.
88.
public class Foo{
public static void main(String sgf[]){
StringBuffer a = new StringBuffer("A");
StringBuffer b = new StringBuffer("B");
operate(a,b);
System.out.println(a+","+b);
}
static void operate(StringBuffer x,StringBuffer y){
x.append(y);
y=x;
}
}
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”.
89.Given
public class Test{
public static void main(String sss[]){
int i=0xFFFFFFF1;
int j=~i;
}
}
What is the value decimal value of j at line 5?
A.0 B.1 C.14 D.-15
F.An error at line 3 causes compilation to fail
G.An error at line 4 causes compilation to fail
90. Which two demonstrate an “is a” relationship?(2)
A.public interface Person{}
public class Employee extends Person{}
B.public interface Shape{}
public interface Retangle extends Shape{}
C.public interface Color{}
public class Shape{private Color color;}
D.public class Species{}
public class Animal{private Species species;}
E.interface Component{}
class Container implements Component{
private Component [] children;
}
91.Given
Package foo;
public class Outer{
public static class Inner{
}
}
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()”.
92.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.
93.Which statement 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 execution.
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.
94. 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. FlowLayout C. GridBagLayout D. CardLayout E. BorderLayout
95. Given:
String foo =”ABCDE”
foo.substring(3);
foo.concat(“XYZ”);
What is the value of the variable foo at line 4?
Shortanswer:
96. Which statement about static inner classes 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 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
97. Which statement is true for the class java.util.ArrayList?
A.The elements in the collection are ordered.
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 collection are guaranteed to be synchronized
98. Which two cannot directly cause a thread to stop executing?
A.exiting from a synchronized block
B.calling the wait method on an object
C.calling the notify method on an object
D.calling a read method on an InputStream object
E.calling the setPriority method on a thread object
99. Given:
public class SyncTest{
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 called by multiple threads
C.check()can return true when multiple threads call setX and setY separately.
D.check() can only return true if SynchTest is changed to allow x and y to be set separately.
100. class A implements Runnable{
int i;
public void run(){
try{
Thread.sleep(50000);
i=10;
}catch(InterruptedException e){}
}
}
public class Test{
public static void main(String a[]){
try{
A a = new A();
Thread t = new Thread(a);
t.start();
int j=a.i;
}catch(Exception e){}
}
}
Which statement at line 17 will ensure that 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();
101. 1.class EnclosingOne{
2. public class InsideOne{}
3. }
4. public class InnerTest{
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.InsideOne ei=eo.new InsideOne();
B.eo.InsideOne ei=eo.new InsideOne();
C.InsideOne ei=EnclosingOne.new InsideOne();
D.EnclosingOne. InsideOne ei=eo.new InsideOne();
102.Which method is an appropriate way to determine the cosine of 42 degrees?
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.cosine(Math.toRadians(42));
103.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)
104.Which statement is true for the class java.util.HashSet?
A.The elements in the collection are ordered.
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 collection are guaranteed to be synchronized.
105. 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.println(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.
106.Given:
1. public class Test{
2. public static void main(String []args){
3. System.out.println(6^3);
4. }
5. }
What is the output?
Answer:
107.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){}
108. Given:
1. int index=1;
2. int[] foo=new int[3];
3. int bar=foo[index];
4 . int baz=bar+index;
What is the result?
A.baz has a value of 0.
B.baz has a value of 1.
C.baz has a value of 2.
D.An exception is thrown.
E.The code will not compile.
109.Which three are equivalent to line 2?
interface foo{
int i=10;
}
A.static i=10;
B.final i=10;
C.public i=10;
D.protected i=10;
E.private i=10;
110. What is the result?
public class A{
int getnumber(int a){
return a+1;
}
}
public class B extends A{
int getnumber(int a){
return a+2;
}
public static void main(String args[]){
A b=new B();
System.out.println(b.getnumber(2));
}
}
A.print 3
B.print 4
C.print 5
D.It will not compile
111. what is the result?
public class Test{
public static void main(String args[]){
String s=new String(”true”);
Boolean b=new Boolean(true);
If(s.equals(b))
{ System.out.println(“hello”);}
}
}
A.print “hello”
B.compile error at line 6
C.compile succeed but print nothing
D.compile succeed but throw exception at runtime
112.What is the result?
public class Test{
static String s=”Hello”;
public static void main(String args[]){
Test t=new Test();
t.methodA(s);
System.out.println(s);
}
void methodA(String s){
s+=”World”;
}
}
A.print “Hello”
B.print “World”
C.print “Hello World”
D.It does not compile
阅读(1462) | 评论(0) | 转发(0) |