Java程序员认证模拟题及详细分析

Share

35. Run a corrected class: java ?Ccs AClass a b c
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?

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.

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.

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

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

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

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

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

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++;

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

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

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

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:

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];

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;
}
}

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

51. Which correctly create an array of five empty Strings?
A. String a[] = new String[5];
for (int i=0;iB. String a []={“”,””,””,””,””};
C. String a[5];
D. String [5] a;
E. String [] a = new String[5];
for (int i = 0 ;iA. an Applet
B. a Component
C. a Container
D. a MenuComponent
E. a panel

53. Which is the return value of Event listener?s method?
A. String B. AWTEvent C. void D. int

54. If we implements MouseListener, which is corrected argument of its method? (short answer)

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

56. Give following fragment.
Outer: for(int i=0; iinner:for(int j=0;jIf(j>1)break outer;
System.out.println(j+”and”+i);
}
Which will be output?
A. 0 and 0 B. 0 and 1 C. 0 and 2 D. 0 and 3
E. 1 and 0 F. 1 and 1 G. 1 and 2 H. 1 and 3
I. 2 and 0 J. 2 and 1 K. 2 and 2 L. 2 and 3

57. 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 termiantes correctly.
C. Program does not terminate.
D.The program will not compile

58. What is written to the standard output given the following statement:
System.out.println(4|7);
Select the right answer:
A.4
B.5
C.6
D.7
E.0

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

60. 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 object.

61. Which can NOT be used in declaring or declaring and initializing an automatic (method local) variable?
A. final
B. static
C. expressions
D. Constants of non-primitive type
E. initialized arrays (such as “ {“Hello”,”Good bye”}”).

62. Given the following incomplete method:
1) public void method(){
2)
3) if (someTestFails()){
4)
5) }
6)
7) }
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.

63. 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))

64. 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;
8) }
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) }
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 Secong a.k.a 2nd
F. The following output:
a is First a.k.a 1st
b is Second a.k.a 2nd

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

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

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

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

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

70.The argument for a class?s main() method is called args, and the class is invoked as follows.
java Example cat
What would be the effect of trying to access args[0] in the main method?
A. The value produced is cat
B. The value produced is java
C. The value produced is Example
D. An object of type NullPointerException is thrown.
E. An object of type ArrayIndexOutofBoundsException is thrown.

71. Which best describes the requirements of a fully encapsulated class?
A. Mehtods 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.

72.Which contains objects without ordering, duplication, or any particular lookup/retrieval mechanism?
A. Map
B. Set
C. List
D. Collection
E. Enumeration

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

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

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

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

====================================================
答案及详细分析:
1。B、E
JAVA的垃圾回收机制是通过一个后台系统级线程对内存分配情况进行跟踪实现的,对程序员来说是透明的,程序员没有任何方式使无用内存显示的、立即的被释放。而且它是在程序运行期间发生的。
答案B告诉我们程序员可以使一个本地变量失去任何意义,例如给本地变量赋值为“null”;答案E告诉我们在程序运行期间不可能完全释放内存。
2。D
第6行将null赋值给a以后,a以前保存的引用所指向的内存空间就失去了作用,它可能被释放。所以对象a可能最早被垃圾回收是在第7行以前,故选择D选项。
3。B
请查阅JAVA类库。getID方法的返回值是“event type”。在认证考试中,总会有类似的书本以外的知识,这只能靠多实践来增长知识了。
4。A、D
控件可以同时使用多个“addXxxxListener”方法加入多个监听器。并且当多个监听器加入到同一控件中时,事件可以响应多个监听器,响应是没有固定顺序的。
5。D、F
本题主要考察考生对流程控制的掌握情况。这是当型循环,条件为真执行,条件为假则退出。循环体至少执行一次,故会输出D。循环体以外的语句总会被执行,故输出F。
6。B.C
在开关语句中,标号总是不被当做语句的一部分,标号的作用就是做为条件判断而已,一旦匹配成功,就执行其后的语句,一直遭遇break语句为止。(包括default语句在内)
7。D、F
IOException异常类是Exception的子类。根据多态性的定义,IOException对象也可以被认为是Exception类型。还要注意在方法声明中抛出异常应用关键字“throws”。
8。D
只有两种情况:大于4时输出“Test1”,小于等于4时输出“Test3”。
9。A、C、D
在正常情况下,打印Test1、Test3、Test4;在产生可捕获异常时打印Test2、Test3、Test4;在产生不可捕获异常时,打印Test3,然后终止程序。注意finally后面的语句总是被执行。
10。B
线程的执行是从方法“run( )”开始的,该方法是由系统调用的。程序员手工调用方法start(),使线程变为可运行状态。
11。A
此题考查内部类及关键字“super”的用法。内部类不能与外部类同名。另外,当B继承A时,A中的构造函数是带参数的,B中缺省构造函数的函数体为空;而JAVA编译器会为空构造函数体自动添加语句“super();”调用父类构造函数,更进一步是调用父类的参数为空的构造函数。而父类中没有参数为空的构造函数。
12。A
此关键字可以在两个线程同时试图访问某一数据时避免数据毁损。

Pages: 1 2 3