打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Sun certificate java programmer Test(3)

scjp模拟试题(三)

 

 

Question No: 1

1.Which statement about the garbage collection mechanism are true?
A. Garbage collection require additional programe 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 explicity and immediately frees the memory used by Java objects.
D. The garbage collection mechanism can free the memory used by Java Object at explection time.
E. The garbage collection system never reclaims memory from objects while are still accessible to running user threads.
答案:BE

 

Question No: 2
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;
8} System.out.println(a);
9} }
In the absence of compiler optimization, which is the earliest point the object a refered is definitely elibile to be garbage collection.
A. before line 3
B.before line 5
C. before line 6
D.before line 7
E. Before line 9
答案:D

 

Question No: 3
3. In the class java.awt.AWTEvent,which is the parent class upon which jdk1.1 awt events are based there is a method called getID which phrase accurately describes the return value of this method?
A. It is a reference to the object directly affected by the cause of the event.
B. It is an indication of the nature of the cause of the event.
C. It is an indication of the position of the mouse when it caused the event.
D. In the case of a mouse click, it is an indication of the text under the mouse at the time of the event.
E. It tells the state of certain keys on the keybord at the time of the event.
F. It is an indication of the time at which the event occurred.
答案: B

Question No: 4
4. 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 addXxxxListener method as many times as is needed, specifying as many different listeners as your design require.
答案: AD

 

Question No: 5
5.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 3
B. Doing it for l is 1
C. Doing it for l is 2
D. Doing it for l is 0
E. Doing it for l is ?C1
F. Finish
答案: DF

 

Question No: 6
6. 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. 1
B. 2
C. 3
D. default
答案: B.C

 

Question No: 7
7. Give incompleted method:
1)
2) { if(unsafe()){//do something…}
3} else if(safe()){//do the other…}
4} }
The method unsafe() well throe 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
答案: DF

Question No: 8
8. 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<4
B. x>4
C. x>9
D. None
答案:D

 

Question No: 9
9. 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 1
B. Test 2
C. Test 3
D. Test 4

答案: ACD

 

Question No: 10
10. Which method you define as the starting point of new thread in a class from which new the thread can be excution?
A. public void start()
B. public void run()
C. public void int()
D. public static void main(String args[])
E. public void runnable()

答案:B

 

Question No: 11
11.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{}

答案:A

 

Question No: 12
12. Which modifier should be applied to a method for the lock of object this to be obtained prior to excution any of the method body?
A. synchronized
B. abstract
C. final
D. static
E. public

答案:A

 

Question No: 13
13. 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){
8} str=s;}}
9) public class Example{
10} public void method(){
11} SubClass s=new SubClass(“hello”);
12} BaseClass b=new BaseClass(“world”);
13} }
14} }
Which line would be cause the error?
A. 9 B. 10 C. 11 D.12

答案:C

 

Question No: 14
14. Which statement is correctly declare a variable a which is suitable for refering to an array of 50 string empty object?
A. String [] a
B. String a[]
C. char a[][]
D. String a[50]
F. Object a[50]

答案: AB

 

Question No: 15
15. Give the following java source fragement:
//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…}

答案: AE

 

Question No: 16
16. 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 x
B. change private int x to static int x
C. Change private int x to protected int x
D. change private int x to final int x

答案:B

 

Question No: 17
17. the piece of preliminary analsis work describes a class that will be used frequently in many unrelated parts of a project
The polygon object is a drawable, A polygon has vertex information stored in a vector, a color, length and width.”
Which Data type would be used?
A. Vector
B. int
C. String
D. Color
E. Date

答案: ABD

Question No: 18
18. A class design requires that a member variable should be accessible only by same package, which modifer word should be used?
A. protected
B. public
C. no modifer
D. private

答案:C

 

Question No: 19
19.Which declares for native method in a java class corrected?
A. public native void method(){}
B. public native void method();
C. public native method();
D. public void method(){native;}
E. public void native method();

答案:B

 

Question No: 20
20. Which modifer 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?

答案: final

Question No: 21
21. Which is the main() method return of a application?
A. String
B. byte
C. char
D. void

答案:D

 

Question No: 22
22. Which is corrected argument of main() method of application?
A. String args
B. String ar[]
C. Char args[][]
D. StringBuffer arg[]

答案:B

 

Question No: 23
23. “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.

答案: public class Employee extends Person

Question No: 24
24. Give the following class defination 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(){}

答案: ABC

Question No: 25
25. 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==t
B. s.equals(t)
C. s==u
D. t.equals(u)

答案: AB

 

Question No: 26
26. 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;

答案: ACE

Question No: 27
27. A socket object has been created and connected to a standard internet service on a remote network server. Which construction give the most suitable means for reading ASCII data online at a time from the socket?
A. InputStream in=s.getInputStream();
B. DataInputStream in=new DataInputstream(s.getInputStream());
C. ByteArrayInputStream in=new ByteArrayInputStream(s.getInputStream());
D. BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));
E. BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()),”8859-1”);

答案:E

 

Question No: 28
28. 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;

答案: BDE

 

Question No: 29
29. 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 compliles 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

答案:E

 

Question No: 30
30. 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 BorderLayout
E. East or West of BorderLayout

答案: CD

Question No: 31
31. 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 BorderLayout
E. East or West of BorderLayout

答案:A

 

Question No: 32
32. An AWT GUI under exposure condition, which one or more method well be invoke when it redraw?
A. paint();
B. update();
C. repaint();
D. drawing();

答案:A

 

Question No: 33
33. Select valid identifier of Java:
A. userName
B. %passwd
C. 3d_game
D. $charge E. this

 

答案: AD

Question No: 34
34. Which are Java keyword?
A. goto
B. null
C. FALSE
D. native
E. const

答案: ABDE

Question No: 35
35. Run a corrected class: java ?Ccs AClass a b c <enter>
Which statement is true?
A. args[0]=”-cs”;
B. args[1]=”a b c”;
C. args[0]=”java”;
D. args[0]=”a”; E. args[1]=?b?

答案:D

 

Question No: 36
36. 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.

答案:C

 

Question No: 37
37. 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.

答案:A

 

Question No: 38
38. Short answer:
The decimal value of i is 12, the octal i value is:

答案: 014

 

Question No: 39
39. Short answer:
The decimal value of i is 7, the hexadecimal i value is:

答案: 0x7

 

Question No: 40
40. Which is the range of char?
A. 27~27-1
B. 0~216-1
C. 0~216
D. 0~28

答案:B

 

Question No: 41
41. Which is the range of int type?
A. -216~216-1
B.- 231~231-1
C. -232~232-1
D. -264~264-1

答案:B

 

Question No: 42
42. Give the following class:
public class Example{
String str=new String(“good”);
char ch[]={
public static void main(String args[]){
Example ex=new Example();
ex.change(ex.str,ex.ch);
System.out.println(ex.str+”and”+ex.ch);
}
public void change(String str,char ch[]){
str=”test ok”;ch[0]=?g?
}
}
Which is the output:
A. good and abc
B. good and gbc
C. test ok and abc
D. test ok and gbc

答案:B

 

Question No: 43
43. 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++;

答案:A

 

Question No: 44
44. FilterOutputStream is the parent class for BufferedOutputStream, DataOutputStream and PrintStream. Which classes are valid argument for the constructor of a FilterOutputStream?
A. InputStream
B. OutputStream
C. File
D. RandomAccessFile
E. StreamTokenizer

答案:B

 

Question No: 45
45. Given a TextArea using a proportional pitch font and constructed like this:
TextArea t=new TextArea(“12345”,5,5);
Which statement is true?
A. The displayed width shows exactly five characters one each line unless otherwise constrained
B. The displayed height is five lines unless otherwise constrained
C. The maximum number of characters in a line will be five
D. The user will be able to edit the character string
E. The displayed string can use multiple fonts

答案:B

 

Question No: 46
46. Given a List using a proportional pitch font and constructed like this:
List l=new List(5,true);
Which statement is true?
A. The displayed item exactly five lines unless otherwise constrained
B. The displayed item is five lines init, but can displayed more than five Item by scroll
C. The maximum number of item in a list will be five.
D. The list is multiple mode

答案:B

 

Question No: 47
47. 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:

答案: this(a,b);

Question No: 48
48. 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];

答案: CDE

Question No: 49
49. 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;
}
}

答案: AE

 

Question No: 50
50. 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 accessor method provided

答案: C

Question No: 51
51
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

答案: ABDE

 

Question No: 52
52
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.

答案: DE

Question No: 53
53
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

答案: AB

 

Question No: 54

54 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.

答案: BD

Question No: 55

55.Given the following,

4. String d = "bookkeeper";

5. d.substring(1,7);

6. d = "w" + d;

7. d.append("woo");

8. System.out.println(d);

what is the result?

A. wookkeewoo

B. wbookkeeper

C. wbookkeewoo

D. wbookkeeperwoo

E. Compilation fails.

F. An exception is thrown at runtime.

 

答案:E

 

Question No: 56

56. Which two statements are true about comparing two instances of the same class, given that the

equals() and hashCode() methods have been properly overridden? (Choose two.)

A. If the equals() method returns true, the hashCode() comparison == must

return true.

B. If the equals() method returns false, the hashCode() comparison != must return

true.

C. If the hashCode() comparison == returns true, the equals() method must return

true.

D. If the hashCode() comparison == returns true, the equals() method might

return true.

E. If the hashCode() comparison != returns true, the equals() method might

return true.

 

答案:A and D

 

Question No: 57

57. Given the following,

1. class X2 {

2. public X2 x;

3. public static void main(String [] args) {

4. X2 x2 = new X2();

5. X2 x3 = new X2();

6. x2.x = x3;

7. x3.x = x2;

8. x2 = new X2();

9. x3 = x2;

10. doComplexStuff();

11. }

12. }

after line 9 runs, how many objects are eligible for garbage collection?

A. 0

B. 1

C. 2

D. 3

E. 4

 

答案:C

 

Question No: 58

58. Which two are true about a method-local inner class?

A. It must be marked final.

B. It can be marked abstract.

C. It can be marked public.

D. It can be marked static.

E. It can access private members of the enclosing class.

 

答案:A E

 

Question No: 59

59. Given the following,

1.public class TestObj {

2. public static void main (String [] args) {

3. Object o = new Object() {

4. public boolean equals(Object obj) {

5. return true;

6. }

7. }

8. System.out.println(o.equals("Fred"));

9. }

10.}

what is the result?

A. An exception occurs at runtime.

B. true

C. fred

D. Compilation fails because of an error on line 3.

E. Compilation fails because of an error on line 4.

F. Compilation fails because of an error on line 8.

G. Compilation fails because of an error on a line other than 3, 4, or 8.

 

答案:G

 

Question No: 60

60. Given the following,

1. class Test {

2.

3. public static void main(String [] args) {

4. printAll(args);

5. }

6.

7. public static void printAll(String[] lines) {

8. for(int i=0;i<lines.length;i++){

9. System.out.println(lines[i]);

10. Thread.currentThread().sleep(1000);

11. }

12. }

13. }

the static method Thread.currentThread() returns a reference to the currently executing

Thread object. What is the result of this code?

A. Each String in the array lines will output, with a 1-second pause.

B. Each String in the array lines will output, with no pause in between because this method is

not executed in a Thread.

C. Each String in the array lines will output, and there is no guarantee there will be a pause

because currentThread() may not retrieve this thread.

D. This code will not compile.

 

答案:D

 

Question No: 61

61. Which two are true?

A. The notifyAll() method must be called from a synchronized context.

B. To call wait(), an object must own the lock on the thread.

C. The notify() method is defined in class java.lang.Thread.

D. When a thread is waiting as a result of wait(), it release its locks.

E. The notify() method causes a thread to immediately release its locks.

F. The difference between notify() and notifyAll() is that notifyAll() notifies

all waiting threads, regardless of the object they’re waiting on.

 

答案:A D

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Java第一次作业
java第一次作业
java反射机制与动态代理(二)
spring入门经典三
Java 类之间的调用(1)
多态的概述和前提条件
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服