computer 版 (精华区)

发信人: gutentag ( Bonjour && deeply in LOVE on the web ), 信区: program
标  题: Java程序员认证模拟题及参考答案
发信站: 听涛站 (2001年06月22日13:50:37 星期五), 站内信件

一.说明
1.考试形式:网络计算机
2.考题形式:多选,单选和简答
3.题量: 60
4.考试时间:120分钟
5.试题给出的答案仅供参考,请对JAVA有一定掌握后再参加认证考试
6.学习java的最后办法就是先学概念、再学习查API、最后写一些程序、做测试题。
二.模拟题:
1.Which statement about the garbage collection mechanism are true?
A.Garbage collection require additional programe code in cases where multipl
e
threads are running.
B.The programmer can indicate that a referance through a local variable is n
o
longer of interest.
C.The programmer has a mechanism that explicity and immediately frees the me
mory
used by Java objects.
D.The garbage collection mechanism can free the memory used by Java Object a
t
explection time.
E.The garbage collection system never reclaims memory from objects while are

still accessible to running user thread.
B、E
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 line is the earliest point the

object a refered is definitely elibile to be garbage collected?
A.3 B.5 C.6 D.7 E.9
C
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 most accerrat
ely
describes in significance of the reture value of this method?
A.It is a reference to the object directly affected by the cause of the even
t.
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 mou
se 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
4. Which statement about listener is true?
A.Most component allow multiple listeners to be added.
B.If mutiple listener be add to a single component,the event only affected o
ne
listener.
C.Component don't allow multiple listeners to be add.
D.The listener mechanism allows you to call an addListener method as many ti
mes
as is needed,specifying as many different listeners as your design requires.

A
5.Give the following code:
public class Example{
public static void main(String args[]){
int I=0;
do{
System.out.println("Doing it for I is:"+ I );
}while(--i);
System.out.println("Finish");
}
}
Which will be output:
A.Doing it for I is 3 B.Doing it for I is 1 C.Doing it for I is 2
D.Doing it for I is 0 E.Doing if for I is -1 F.Finish
D,E
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
7.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
F.public void methodName() throws Exception
D,F
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 of x would produce of output "Test 2"?
A.x4 C.x>9 D.None
D
9.Give the following method:
public void example(){
try{
unsafe();
System.out.println("Test 1");
}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
A,B,D
10.Which method you define as the starting point of new thread in a class fr
om
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
11.What cause the current thread to stop excutings?
A.thread of higher priority become ready. B.method sleep() be called.
C.method stop() be called D.method suspend() be called.
E.method wait() be called
B,C,D,E
12.Which modifier should be applied to a method for the lock of object this 
to be
obtained prior to excution any of the mehod body?
A.synchronized B.abstract C.final D.static E.public
A
13.The following code is entire contents of a file called Example.java,cause
s
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) }
15) }
16) }
Which line would be cause the error? A.9 B.10 C.11 D.12
考查:类中定义类、类名与文件名等
14.Which statement is correctly declare a variable a which is suitable for
refering to an array of 30 string empty object?
A.String []a B.String a[] D.char a[][] E.String a[50] F.Object a[50]
A,B
15.Give the following java sourse fragement:
//point x
public class Interesting{
//do something
}
which statement is correctly Java syntax ant 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..
.}
A,E(关于类文件的几部分组成,参见LS-275教程第一章)
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 th
is.x
be 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 in
t x
曾经在认证测试中多次出现,答案为D,但这是一道错误的题。
17.The piece of preliminary analyse 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
A,B,C(此外可能会考根据上述描述定义类头)
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
19.Which declares for a native method in a java class corrected?
A.public void method native (){ } B.public native void method();
C.public native method(); D.public void method(){native;}
E.public void native method();
B
20.Which modifer should be applied to a declaration of a class member variab
le
for the value of variable to remain constant after the creation of the
object?(short answer)
static
21.Which is the main() method's return of a application?
A.String B.byte C.char D.void
D
22.Which is corrected argument of main() method of a applicaton?
A.String args B.String ar[] C.Char args[][] D.StringBuffer arg[]
B
23."The Employee object is a person,An Employee has appointment store in a
vector,a hire date and a number of dependents."
short anwser:use shortest statement define a class of Employee.
Public Employee extends person
24.Give the following class defination inseparate source files:
public class Example{
public Example(){//do something}
protected Example(){// 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() E.private otherMethod(){}
考察子类中与父类的方法定义冲突,请多调试。
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.equal(t); C.s==u D.t.equal(u)
(上机)
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's result is true?
A.a= =b; B.a= =x; C.y= =z; D.x= =y;
E.a= =10.0;
(上机)
27.A socket object has been created and connected to a standard internet sev
ice
on a remote network server.Which construction give the most suitable means f
or
reading ASCII data one line 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.getInputStrea
m()));
E.BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStrea
m()),"8859-1");
B
28.String s="Example String";
Which operation is legal?
A.s>>>=3; B.int =s.length(); C.s[3]="x";
D.String short s=s.trim(); E.String t="root"+s;
上机
29.Give: String str="goodby";
Which operation is legal?
A.char c=s[3]; B.int i=s.length(); C.s>>=2;
D.String lower s=s.toLowerCase(); E.s+="long ago";
上机
30.What use to position a Button in a Frame,width of Button is affected by t
he
Frame size,which Layout Button will be set to?
A.FlowLayout; B.GridLayout; C.North of BorderLayout
D.South of BorderLayout D.Ease or West of BorderLayout
31.What use to position a Button in a Frame,size of Button is not affected b
y the
Frame size,which Layout Button will be set to?
A.FlowLayout; B.GridLayout; C.North of BorderLayout
D.South of BorderLayout D.Ease or West of BorderLayout
(30、31测试几种布局管理器对图形形状在改变容器大小的条件下的影响,上机)
32.An AWT GUI under exposure condition,which one or more method will be invo
k
when it redraw?
A.paint(); B.update(); C.repaint(); D.drawing();
C
33.Select valid identifier of Java:
A.userName B.%passwd C.3d_game D.$charge E.this
A
34.Which are Java keyword?
A.goto B.null C.FALSE D.native E.const
A,D,E
35.Run a corrected class:java -cs 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 zearo.
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 zearo.
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 is:
(参考:0X7)
40.Which is the range of char?
A.2-7~27-1 B.0~216-1 C.0~216 D.0~28
 (参考41)
41.Which is the range of int type?
A.2-16~2 16-1 B.2-31~ 2 31-1 C.2-32~2 32-1 D.2-64~2 64-1
清楚type,char,long等基本数据类型的标识范围,上述2-64是264
42.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);
}
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 pas
sed
via command line to a Java Application, excluding the name of the class that
 is
being invoked?
A.int count = args.length; B.int count = args.length - l;
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 a valid argument for the

constructor of a FilterOutputStream?
A.InputStream B.OutputStream C.File
D.RandomAccessFile E.StreamTokenizer
(参考API)
 
45.Given a TextArea using a proportional pitch font and constructed like thi
s:
TextArea t = new TextArea("12345", 5, 5);
Which statement is true?
A.the displayed width shows exactly five characters one ach line unless othe
rwise
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 TextArea using a proportional pitch font and constructed like thi
s:
List l=new List(5,true); Which statement is true?
A.the displayed item exactly five line unless otherwise constrained
B.The displayed item is five lines init.but can displayed more than five Ite
m by
C.The maximum number of item in a list will be five.
D.The list is multiple mode
 (上机试验,参考:A,D)
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;
}
}
What is the most concise way to code the "do everything..."part of the
constructor taking two arguments? (short answer)
This(x,y);
 
48.Which correctly create a two dimensional array of integers?
A.int a[][] = new int[10,10]
B.int a[10][10] = new int[][];
C.int a[][] = new int [10][10];
D.int []a[] = new int [10][10];
(数组的定义,参考:C,D)
49.Which are correct class declarations? Assume in each case that the text
constitutes the entire contents of a file called Fred.java on a system with 
a
case-significant file system.
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 accessi
ble
for direct access by any subclasses of this class, but otherwise not by clas
ses
which are not members of the same package. What should be done to achieve th
is?
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
 (这种考题是最简单的,注意:A,B,C,D四种情况都可能考)
51.Which correctly create an array of five empty Strings?
A.String a [] = new String [5];
for (int i = 0; i >" 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
A.1010 0000 0000 0000 0000 0000 0000 0000>>>4 give
0000 1010 0000 0000 0000 0000 0000 0000
(>>,>>的使用,上机无法得到正确答案。关键是掌握这几个运算符合的实际含义,如:
是否有符号?考试方式可能是文字描述方式)
A.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;i1) break outer;
System.out.println(j+"and"+i);
}
(上机,非常简单,但类似的题一般会考2道题左右)
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.FilterInputStream is the parent class for BufferedInputStream, DataInputS
tream
and PrintStream. Which classes are a valid argument for the constructor of a

FilterOutputStream?
A.InputStream B.OutputStream C.File
D.RandomAccessFile E.StreamTokenizer
(查FilterInputStream的构造函数即可,希望能了解与IO相关的几个主要类之间的关系
,如
谁套谁。)
58.Which is the main()method return?
A. String B.void C.char D.int
(答案:B)
59.Look the inheritance ralation:
person
|
----------
| |
man woman
In a sourse 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 ralation:
person
|
----------
| |
man woman
In a sourse 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.
(考察子类与父类初始化关系,答案为A,如果是父子关系呢?)
 
 
 
 
 
 
 
中国JAVA阵线
 
2000年4月18日

--
【Bonjour && deeply in LOVE on the web】 

                春が来た、春が来た、どこに来た。                               
                山に来た、郷に来た、野にも来た。


※ 来源:·听涛站 tingtao.dhs.org·[FROM: 匿名天使的家] 
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.410毫秒