打开APP
userphoto
未登录

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

开通VIP
SCJP试题分析修正版

1.
1) public class ReturnIt{
2) returnType methodA(byte x, double y){
3) return (short)x/y*2;
4) }
5) }
what is valid returnType for methodA in line 2?
题意:第2行中methodA方的正确返回值类型是什么?
分析:这是一道考察基础知识的问题,比较简单,涉及强制类型转换和表达式数据类型的转换和升级。强制类型转换的方法是在变量或数值前加上需要转换的类型,如(int)12.23 则duble类型的数值被强行转化为int型,当然此时回丢失信息。表达式数据类型的转换原则是在不出现信息丢失的情况下自动升级到一种更长的形式。
解答:判断return后的表达式的值类型即可,(short)的强制转换仅为x,根据自动提升原则表达式的值被提升到y的类型既double,所以答案为double 。
注意:(1)、不带尾巴的数值容易被忽视他的真实类型,比如12和12.0,其中12为int或short型,12.0为duble型。
(2)、二元操作符(如 、-、*、/)当其操作的对象是基本数据类型时,会把其操作的变量自动提升为至少到int型,主要针对byte和short型。例如如下代码会出错:
short a , b, c;
a = 1;
b = 2;
c = a+ b;//编译指示这行出错了,possible loss of precision
示例:w01.java
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. public double getNum(float d){return 4.0d;}
题意: 哪一种方法定义放在第6行,会产生编译错误?
分析: 此为一道同时考察overload和override的问题。overload是利用同一个函数名和不同的参数形式来完成不同的功能,不同的参数形式的意思是:有和无参数的区别;参数个数的区别;参数类型的区别和参数的排列方式的区别。Overload不能利用返回值来区分。Overload现象可出现在同类或父类与继承类中。override的是类继承过程中出现的现象,是对父类方法的改写,所以必须满足以下条件:1、方法名相同;2、返回类型相同;3、参数完全相同。
解答:分别将答案放在第6行,A表示对super类的getNum方法进行override,正确;B语句因为参数与父类的同名函数的参数相同所以不是overload,而返回值与父类同名函数返回值不同所以不是override,进而出错。C表示对继承自super类的getNum方法进行overload,正确;D同C
注意: 考察多个知识点时要综合分析,但首先要保持清醒,弄清考察的意向。
示例: w02.java
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?
题意: 结果是什么?
分析: 也是属于基础知识的考察,请参考运算符说明部分。=为赋值,表达式本身的值为=号左边的值;==为比较,表达式本身的值为true或false。If语句后面需要一个boolean的值来判断。
解答:compile error
注意:
示例: w03.java
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
题意: 结果是什么?
分析: 考察try—catch—finally语句的语法。一般,try语句块中产生异常,由catch语句捕获异常进行处理。关于finally语句,sun-275的教材中解释的很明确,它的代码块“总是”被执行,而不考虑有没有异常发生。不执行finally代码块的情况只有一种,就是VM结束(执行System.exit()方法和机器关闭)。如果一个return语句嵌入在catch快内,则finally快的代码在return之前执行。

解答: B
注意: 若有System.exit()出现要注意。
示例: w04.java
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?
题意: 在第24行处,output的值是什么。
分析: 本题考察static类型的变量和try—catch语句的执行。try—catch语句参见第4题的讲解。所谓静态,据本人理解指的是其在内存中的位置是固定的,即程序装载完成后所有静态变量就固定于某一内存地址中,它们不随着类的实例化而随对象的地址而变动,所以有人说静态变量属于类而不属于对象。所以静态方法可以不对类进行实例化而直接调用,静态变量也可以不对其所属类进行实例化而直接使用。而多次实例化的对象使用静态变量时,实际是使用同一内存地址的内容。
解答: 从主程序的调用入手分析。1、Foo(0)调用Foo函数,并将0传给Foo函数的i变量。2、运行try语句块,比较i==1不成立,执行if后面的语句output ="1",此时output的值为“1”。3、try语句没有异常抛出,在执行finally语句后即结束。finally语句改变output的值为“3”。4、执行try语句外面的语句output ="4",此时output的值为“4”,Foo(0)调用结束。5、Foo(1)调用Foo函数并将1传给Foo函数的i变量。6、运行try语句块,比较i==1成立,执行if语句块内的语句。7、抛出一个异常。8、catch语句立刻捕获异常并执行output ="2",此时output的值为“2”。9、继续向下执行return准备结束Foo函数,但是return前要执行finally语句的内容output ="3",此时output的值为“3”。然后结束Foo函数。在第24行处output的值为“3”。
注意: 答案时应该写“”?
示例: w05.java
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?
题意: 输出是什么?
分析: 本题比较简单,只是用odd这样的函数名迷惑视线,其实odd函数定义的类型是int,所以放在if里判断自然会产生错误。
解答: complime error
注意: if为常考内容(仅仅从模拟考试题得出的结论,不代表实际考试情况)
示例: w06.java
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?
题意: 如果methodA()抛出一个IOException,程序的结果是什么?
分析: 多个catch语句的情况是按顺序判断异常的类型,直到找到相应的catch语句块去执行,然后结束。
解答: 既然methodA抛出的是IOException异常,那么catch(IOException e)捕获到并执行System.out.println("caught IOException")然后结束。所以答案是 caught IOException。
注意: 若调换catch(IOException e)和catch(Exception e)的顺序会产生编译错误。因为如果调换以后catch(IOException e)语句块的内容永远不会被执行。
示例: w07.java
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. i=5 j=5
C. i=6 j=4
D. i=5 j=6
E. i=6 j=6
题意: 执行结束后,i和j的值分别是什么?
分析: 说实话,我开始以为这题还有点复杂,是考x 和 x的区别以及continue语句的作用,可是经过分析发现其实知不知道以上两个知识点对答案并没有影响,简单的计算一下就OK了,i和的值经过循环依次为:2、9;3、8;4、7;5、6。此时i<5不成立,程序结束,而已。
解答: i=5,j=6 。答案为D
注意: 还是要注意一下x 和 x的区别,x 表达式的值为x原值, x表达式的值为x经 1计算后的值。但经过x 或 x后x本身的值都比原值增加了1。例如:int a=1,b=1; int c=a ;int d= b;最后a为2,b为2,c为1,d为2。还有就是continue用于循环块内表示本次循环结束(注意不是循环结束!)下次循环开始,它后面的语句就不执行了。
示例: w08.java
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;
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)
题意: (此题有拼写错误大概意思是)哪一行是引用对象明确的允许被垃圾收集机收集的最早的位置
分析: 一个对象成为垃圾有两种情况,一是失去引用;一是离开了作用域。
解答: 程序在第3行new了一个值为3.14的float对象,并用object引用类型o指向它。第4行声明一个大小为1的object类型的数组oa,第5行将o的引用传递给oa的第一个成员oa[0]。注意此时有两个引用o和oa[0]指向实际值为3.14的float对象。第6行让o为空,既o失去对象的引用,也就是float对象失去一个引用o。此时float对象还有一个引用oa[0],用oa[0]依然可以访问。第7行,oa[0]置空,此时float对象已经没有引用指向它,既变为垃圾,可以被收集。所以答案是D。
注意: 注意对象和对象的引用的区别。
示例: 无
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?
题意: 结果是什么?
分析: 接口和实现的问题,接口中的数据成员都是static和final型的,即使接口中不用这两个关键字定义。接口中的所有方法都是public型的,并且没有被实现,需要在直接继承他的类中全部定义。
解答: 关键分析8、9、10行。第8行i=test.k;test是Test类的一个实例,Test是接口Foo的实现类,所以Test类拥有static final类型的k数据成员,test对Test类的k成员进行调用是合法的,所以实际i被附值为0。第9行在Test类的静态方法main中调用静态数据k当然也没有错误。第10行调用同一个文件中的接口中的静态成员也是合法的,所以程序会成功编译,没有错误。
注意: 示例中可以同时使用注释1和注释2的语句,或单独使用注释1的语句。单独使用注释2的附值语句时,会出现编译错误,这是因为试图给final变量附值引起的。
-------------------------------------------------------------------------------------------------------------------------------
Choose the three valid identifiers from those listed below.
A. IDoLikeTheLongNameClass
B. $byte
C. const
D. _ok
E. 3_case
解答:A, B, D
点评:Java中的标示符必须是字母、美元符($)或下划线(_)开头。关键字与保留字不能作为标示符。选项C中的const是Java的保留字,所以不能作标示符。选项E中的3_case以数字开头,违反了Java的规则。
例题2:
How can you force garbage collection of an object?
A. Garbage collection cannot be forced
B. Call System.gc().
C. Call System.gc(), passing in a reference to the object to be garbage collected.
D. Call Runtime.gc().
E. Set all references to the object to new values(null, for example).
解答:A
点评:在Java中垃圾收集是不能被强迫立即执行的。调用System.gc()或Runtime.gc()静态方法不能保证垃圾收集器的立即执行,因为,也许存在着更高优先级的线程。所以选项B、D不正确。选项C的错误在于,System.gc()方法是不接受参数的。选项E中的方法可以使对象在下次垃圾收集器运行时被收集。
例题3:
Consider the following class:
1. class Test(int i) {
2. void test(int i) {
3. System.out.println(“I am an int.”);
4. }
5. void test(String s) {
6. System.out.println(“I am a string.”);
7. }
8.
9. public static void main(String args[]) {
10. Test t=new Test();
11. char ch=“y”;
12. t.test(ch);
13. }
14. }
Which of the statements below is true?(Choose one.)
A. Line 5 will not compile, because void methods cannot be overridden.
B. Line 12 will not compile, because there is no version of test() that rakes a char argument.
C. The code will compile but will throw an exception at line 12.
D. The code will compile and produce the following output: I am an int.
E. The code will compile and produce the following output: I am a String.
解答:D
点评:在第12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运行时传给void test(int i)方法。
例题4:
Which of the following lines of code will compile without error?
A.
int i=0;
if (i) {
System.out.println(“Hi”);
}
B.
boolean b=true;
boolean b2=true;
if(b==b2) {
System.out.println(“So true”);
}
C.
int i=1;
int j=2;
if(i==1|| j==2)
System.out.println(“OK”);
D.
int i=1;
int j=2;
if (i==1 &| j==2)
System.out.println(“OK”);
解答:B, C
点评:选项A错,因为if语句后需要一个boolean类型的表达式。逻辑操作有^、&、| 和 &&、||,但是“&|”是非法的,所以选项D不正确。
例题5:
Which two demonstrate a "has a" relationship? (Choose two)
A. public interface Person { }
 

public class Employee extends Person{ }
B. public interface Shape { }
public interface Rectandle extends Shape { }
C. public interface Colorable { }
public class Shape implements Colorable
{ }
D. public class Species{ }
public class Animal{private Species species;}
E. interface Component{ }
class Container implements Component{
private Component[] children;
}
解答:D, E
点评: 在Java中代码重用有两种可能的方式,即组合(“has a”关系)和继承(“is a”关系)。“has a”关系是通过定义类的属性的方式实现的;而“is a”关系是通过类继承实现的。本例中选项A、B、C体现了“is a”关系;选项D、E体现了“has a”关系。
例题6:
Which two statements are true for the class java.util.TreeSet? (Choose two)
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
解答:A, C
点评:TreeSet类实现了Set接口。Set的特点是其中的元素惟一,选项C正确。由于采用了树形存储方式,将元素有序地组织起来,所以选项A也正确。
例题7:
True or False: Readers have methods that can read and return floats and doubles.
A. Ture
B. False
解答:B
点评: Reader/Writer只处理Unicode字符的输入输出。float和double可以通过stream进行I/O.
例题8:
What does the following paint() method draw?
1. public void paint(Graphics g) {
2. g.drawString(“Any question”, 10, 0);
3. }
A. The string “Any question?”, with its top-left corner at 10,0
B. A little squiggle coming down from the top of the component.
解答:B
点评:drawString(String str, int x, int y)方法是使用当前的颜色和字符,将str的内容显示出来,并且最左的字符的基线从(x,y)开始。在本题中,y=0,所以基线位于最顶端。我们只能看到下行字母的一部分,即字母‘y’、‘q’的下半部分。
例题9:
What happens when you try to compile and run the following application? Choose all correct options.
public class Z {
 public static void main(String[] args) {
  new Z();
 }
 Z() {
  Z alias1 = this;
  Z alias2 = this;
  synchronized (alias1) {
   try {
    alias2.wait();
    System.out.println("DONE WAITING");
   }
   catch (InterruptedException e) {
    System.out.println("INTERRUPTED");
   }
   catch (Exception e) {
    System.out.println("OTHER EXCEPTION");
   }
   finally {
    System.out.println("FINALLY");
   }
  }
  System.out.println("ALL DONE");
 }
}
A. The application compiles but doesn't print anything.
B. The application compiles and print “DONE WAITING”
C. The application compiles and print “FINALLY”
D. The application compiles and print “ALL DONE”
E. The application compiles and print “INTERRUPTED”
解答:A
点评:在Java中,每一个对象都有锁。任何时候,该锁都至多由一个线程控制。由于alias1与alias2指向同一对象Z,在执行第11行前,线程拥有对象Z的锁。在执行完第11行以后,该线程释放了对象Z的锁,进入等待池。但此后没有线程调用对象Z的notify()和notifyAll()方法,所以该进程一直处于等待状态,没有输出。
例题10:
Which statement or statements are true about the code listed below? Choose three.
public class MyTextArea extends TextArea {
public MyTextArea(int nrows, int ncols) {
 enableEvents(AWTEvent.TEXT_EVENT_MASK);
 }
public void processTextEvents(TextEvent te) {
  System.out.println(Processing a text event.);
 }
}
A. The source code must appear in a file called MyTextArea.java
B. Between lines 2 and 3, a call should be made to super(nrows, ncols) so that the new component will have the correct size.
C. At line 6, the return type of processTextEvent() should be declared boolean, not void.
D. Between lines 7 and 8, the following code should appear: return true.
E. Between lines 7 and 8, the following code should appear: super.processTextEvent(te).
解答:A, B, E
点评:由于类是public,所以文件名必须与之对应,选项A正确。如果不在2、3行之间加上super(nrows,ncols)的话,则会调用无参数构建器TextArea(), 使nrows、ncols信息丢失,故选项B正确。在Java2中,所有的事件处理方法都不返回值,选项C、D错误。选项E正确,因为如果不加super.processTextEvent(te),注册的listener将不会被唤醒。
--------------------------------------------------------------------------------------------------------------------------------

41、Which of the following statements are legal?
A. long l = 4990;
B. int i = 4L;
C. float f = 1.1;
D. double d = 34.4;
E. double t = 0.9F.
(ade)
题目:下面的哪些声明是合法的。
此题的考点是数字的表示法和基本数据类型的类型自动转换,没有小数点的数字被认为是int型数,带有小数点的数被认为是double型的数,其它的使用在数字后面加一个字母表示数据类型,加l或者L是long型,加d或者D是double,加f或者F是float,可以将低精度的数字赋值给高精度的变量,反之则需要进行强制类型转换,例如将int,short,byte赋值给long型时不需要显式的类型转换,反之,将long型数赋值给byte,short,int型时需要强制转换(int a=(int)123L;)。
 
42、
public class Parent {
int change() {…}
}
class Child extends Parent {
 
}
Which methods can be added into class Child?
A. public int change(){}
B. int chang(int i){}
C. private int change(){}
D. abstract int chang(){}
(ab)
题目:哪些方法可被加入类Child。
这个题目的问题在第35题中有详尽的叙述。需要注意的是答案D的内容,子类可以重写父类的方法并将之声明为抽象方法,但是这引发的问题是类必须声明为抽象类,否则编译不能通过,而且抽象方法不能有方法体,也就是方法声明后面不能带上那两个大括号({}),这些D都不能满足。
 
43、
class Parent {
String one, two;
public Parent(String a, String b){
one = a;
two = b;
}
public void print(){ System.out.println(one); }
}
public class Child extends Parent {
public Child(String a, String b){
super(a,b);
}
public void print(){
System.out.println(one " to " two);
}
public static void main(String arg[]){
Parent p = new Parent("south", "north");
Parent t = new Child("east", "west");
p.print();
t.print();
}
}
Which of the following is correct?
A. Cause error during compilation.
B. south
east
C. south to north
east to west
D. south to north
east
E. south
east to west
(e)
题目:下面的哪些正确。
A. 在编译时出错。
这个题目涉及继承时的多态性问题,在前面的问题中已经有讲述,要注意的是语句t.print();在运行时t实际指向的是一个Child对象,即java在运行时决定变量的实际类型,而在编译时t是一个Parent对象,因此,如果子类Child中有父类中没有的方法,例如printAll(),那么不能使用t.printAll()。参见12题的叙述。
 
44、A Button is positioned in a Frame. Only height of the Button is affected by the Frame while the width is not. Which layout manager should be used?
A. FlowLayout
B. CardLayout
C. North and South of BorderLayout
D. East and West of BorderLayout
E. GridLayout
(d)
题目:一个按钮放在一个框架中,在框架改变时只影响按钮的高度而宽度不受影响,应该使用哪个布局管理器?
这个还是布局管理器的问题,流布局管理器(FlowLayout)将根据框架的大小随时调整它里面的组件的大小,包括高度和宽度,这个管理器不会约束组件的大小,而是允许他们获得自己的最佳大小,一行满了以后将在下一行放置组件;卡片管理器(CardLayout)一次显式一个加入的组件(根据加入时的关键字);网格管理器(GridLayout)将容器划分为固定的网格,容器大小的改变将影响所有组件的大小,每个组件的大小都会同等地变化;边界管理器(BorderLayout)将容器划分为五个区域,分为东南西北和中间,东西区域的宽度为该区域里面组件的最佳宽度,高度为容器的高度减去南北区域的高度,这是一个可能变化的值,而南北区域的宽度为容器的整个宽度,高度为组件的最佳高度,中间区域的高度为容器的高度减去南北区域的高度,宽度为容器的宽度减去东西区域的宽度。
 
45、Given the following code:
1) class Parent {
2) private String name;
3) public Parent(){}
4) }
5) public class Child extends Parent {
6) private String department;
7) public Child() {}
8) public String getValue(){ return name; }
9) public static void main(String arg[]) {
10) Parent p = new Parent();
11) }
12) }
Which line will cause error?
A. line 3
B. line 6
C. line 7
D. line 8
E. line 10
(d)
题目:给出下面的代码:
哪些行将导致错误。
第8行的getValue()试图访问父类的私有变量,错误,参看前面有关变量类型及其作用域的叙述。
 
 

46、The variable "result" is boolean. Which expressions are legal?
A. result = true;
B. if ( result ) { // do something... }
C. if ( result!= 0 ) { // so something... }
D. result = 1
(ab)
题目:变量"result"是一个boolean型的值,下面的哪些表达式是合法的。
Java的boolean不同于c或者c 中的布尔值,在java中boolean值就是boolean值,不能将其它类型的值当作boolean处理。
 
47、Class Teacher and Student are subclass of class Person.
Person p;
Teacher t;
Student s;
p, t and s are all non-null.
if(t instanceof Person) { s = (Student)t; }
What is the result of this sentence?
A. It will construct a Student object.
B. The expression is legal.
C. It is illegal at compilation.
D. It is legal at compilation but possible illegal at runtime.
(c)
题目:类Teacher和Student都是类Person的子类
p,t和s都是非空值
这个语句导致的结果是什么
A. 将构造一个Student对象。
B. 表达式合法。
C. 编译时非法。
D. 编译时合法而在运行时可能非法。
instanceof操作符的作用是判断一个变量是否是右操作数指出的类的一个对象,由于java语言的多态性使得可以用一个子类的实例赋值给一个父类的变量,而在一些情况下需要判断变量到底是一个什么类型的对象,这时就可以使用instanceof了。当左操作数是右操作数指出的类的实例或者是子类的实例时都返回真,如果是将一个子类的实例赋值给一个父类的变量,用instanceof判断该变量是否是子类的一个实例时也将返回真。此题中的if语句的判断没有问题,而且将返回真,但是后面的类型转换是非法的,因为t是一个Teacher对象,它不能被强制转换为一个Student对象,即使这两个类有共同的父类。如果是将t转换为一个Person对象则可以,而且不需要强制转换。这个错误在编译时就可以发现,因此编译不能通过。
 
48、Given the following class:
public class Sample{
long length;
public Sample(long l){ length = l; }
public static void main(String arg[]){
Sample s1, s2, s3;
s1 = new Sample(21L);
s2 = new Sample(21L);
s3 = s2;
long m = 21L;
}
}
Which expression returns true?
A. s1 == s2;
B. s2 == s3;
C. m == s1;
D. s1.equals(m).
(b)
题目:给出下面的类:
哪个表达式返回true。
前面已经叙述过==操作符和String的equals()方法的特点,另外==操作符两边的操作数必须是同一类型的(可以是父子类之间)才能编译通过。
 
49、Given the following expression about List.
List l = new List(6,true);
Which statements are ture?
A. The visible rows of the list is 6 unless otherwise constrained.
B. The maximum number of characters in a line will be 6.
C. The list allows users to make multiple selections
D. The list can be selected only one item.
(ac)
题目:给出下面有关List的表达式:
哪些叙述是对的。
A. 在没有其它的约束的条件下该列表将有6行可见。
B. 一行的最大字符数是6
C. 列表将允许用户多选。
D. 列表只能有一项被选中。
List组件的该构造方法的第一个参数的意思是它的初始显式行数,如果该值为0则显示4行,第二个参数是指定该组件是否可以多选,如果值为true则是可以多选,如果不指定则缺省是不能多选。
 
50、Given the following code:
class Person {
String name,department;
public void printValue(){
System.out.println("name is " name);
System.out.println("department is " department);
}
}
public class Teacher extends Person {
int salary;
public void printValue(){
// doing the same as in the parent method printValue()
// including print the value of name and department.
System.out.println("salary is " salary);
}
}
Which expression can be added at the "doing the same as..." part of the method printValue()?
A. printValue();
B. this.printValue();
C. person.printValue();
D. super.printValue().
(d)
题目:给出下面的代码:
下面的哪些表达式可以加入printValue()方法的"doing the same as..."部分。
子类可以重写父类的方法,在子类的对应方法或其它方法中要调用被重写的方法需要在该方法前面加上”super.”进行调用,如果调用的是没有被重写的方法,则不需要加上super.进行调用,而直接写方法就可以。这里要指出的是java支持方法的递归调用,因此答案a和b在语法上是没有错误的,但是不符合题目代码中说明处的要求:即做和父类的方法中相同的事情――打印名字和部门,严格来说也可以选a和b。
 
 

51、Which is not a method of the class InputStream?
A. int read(byte[])
B. void flush()
C. void close()
D. int available()
(b)
题目:下面哪个不是InputStream类中的方法
这个题目没有什么好说的,要求熟悉java API中的一些基本类,题目中的InputStream是所有输入流的父类,所有要很熟悉,参看JDK的API文档。方法void flush()是缓冲输出流的基本方法,作用是强制将流缓冲区中的当前内容强制输出。
 
52、Which class is not subclass of FilterInputStream?
A. DataInputStream
B. BufferedInputStream
C. PushbackInputStream
D. FileInputStream
(d)
题目:
哪个不是FilterInputStream的子类。
此题也是要求熟悉API基础类。Java基础API中的FilterInputStream 的已知子类有:BufferedInputStream, CheckedInputStream, CipherInputStream, DataInputStream, DigestInputStream, InflaterInputStream, LineNumberInputStream, ProgressMonitorInputStream, PushbackInputStream 。
 
53、Which classes can be used as the argument of the constructor of the class FileInputStream?
A. InputStream
B. File
C. FileOutputStream
D. String
(bd)
题目:哪些类可以作为FileInputStream类的构造方法的参数。
此题同样是要求熟悉基础API,FileInputStream类的构造方法有三个,可接受的参数分别是:File、FileDescriptor、String类的一个对象。
 
54、Which classes can be used as the argument of the constructor of the class FilterInputStream?
A. FilterOutputStream
B. File
C. InputStream
D. RandomAccessFile
(c)
题目:哪些类可以作为FilterInputStream类的构造方法的参数。
FilterInputStream的构造方法只有一个,其参数是一个InputStream对象。
 
55、Given the following code fragment:
1) switch(m)
2) { case 0: System.out.println("case 0");
3) case 1: System.out.println("case 1"); break;
4) case 2:
5) default: System.out.println("default");
6) }
Which value of m would cause "default" to be the output?
A. 0
B. 1
C. 2
D. 3
(cd)
题目:给出下面的代码片断:
m为哪些值将导致"default"输出。
此题考察switch语句的用法,switch的判断的条件必须是一个int型值,也可以是byte、short、char型的值,case中需要注意的是一个case后面一般要接一个break语句才能结束判断,否则将继续执行其它case而不进行任何判断,如果没有任何值符合case列出的判断,则执行default的语句,default是可选的,可以没有,如果没有default而又没有任何值匹配case中列出的值则switch不执行任何语句。
 
56、Given the uncompleted method:
1)
2) { success = connect();
3) if (success==-1) {
4) throw new TimedOutException();
5) }
6)}
TimedOutException is not a RuntimeException. Which can complete the method of declaration when added at line 1?
A. public void method()
B. public void method() throws Exception
C. public void method() throws TimedOutException
D. public void method() throw TimedOutException
E. public throw TimedOutException void method()
(bc)
题目:给出下面的不完整的方法:
TimedOutException 不是一个RuntimeException。下面的哪些声明可以被加入第一行完成此方法的声明。
如果程序在运行的过程中抛出异常,而这个异常又不是RuntimeException或者Error,那么程序必须捕获这个异常进行处理或者声明抛弃(throws)该异常,捕获异常可以使用try{}catch(){}语句,而抛弃异常在方法声明是声明,在方法的声明后面加上throws XxxxException,抛弃多个异常时在各异常间使用逗号(,)分隔,题目中的程序在运行时抛出的不是一个RuntimeException,所有必须捕获或者抛弃,而程序又没有捕获,所有应该在方法声明中声明抛弃。由于Exception是所有异常的父类,所有当然也可以代表RuntimeException了。
 
57、Which of the following answer is correct to express the value 10 in hexadecimal number?
A. 0xA
B. 0x16
C. 0A
D. 016
(a)
题目:下面的哪些答案可以正确表示一个十六进制数字10。
十六进制数以0x开头,以0开头的是八进制数。十六进制表示中的a,b,c,d,e,f依次为10,11,12,13,14,15。
 
58、Which statements about thread are true?
 

A. Once a thread is created, it can star running immediately.
B. To use the start() method makes a thread runnable, but it does not necessarily start immediately.
C. When a thread stops running because of pre-emptive, it is placed at the front end of the runnable queue.
D. A thread may cease to be ready for a variety of reasons.
(bd)
题目:有关线程的哪些叙述是对的。
A. 一旦一个线程被创建,它就立即开始运行。
B. 使用start()方法可以使一个线程成为可运行的,但是它不一定立即开始运行。
C. 当一个线程因为抢先机制而停止运行,它被放在可运行队列的前面。
D. 一个线程可能因为不同的原因停止(cease)并进入就绪状态。
一个新创建的线程并不是自动的开始运行的,必须调用它的start()方法使之将线程放入可运行态(runnable state),这只是意味着该线程可为JVM的线程调度程序调度而不是意味着它可以立即运行。线程的调度是抢先式的,而不是分时 间片式的。具有比当前运行线程高优先级的线程可以使当前线程停止运行而进入就绪状态,不同优先级的线程间是抢先式的,而同级线程间是轮转式的。一个线程停止运行可以是因为不同原因,可能是因为更高优先级线程的抢占,也可能是因为调用sleep()方法,而即使是因为抢先而停止也不一定就进入可运行队列的前面,因为同级线程是轮换式的,它的运行可能就是因为轮换,而它因抢占而停止后只能在轮换队列中排队而不能排在前面。
 
59、The method resume() is responsible for resuming which thread's execution?
A. The thread which is stopped by calling method stop()
B. The thread which is stopped by calling method sleep()
C. The thread which is stopped by calling method wait()
D. The thread which is stopped by calling method suspend()
(d)
题目:方法resume()负责恢复哪些线程的执行。
A. 通过调用stop()方法而停止的线程。
B. 通过调用sleep()方法而停止运行的线程。
C. 通过调用wait()方法而停止运行的线程。
D. 通过调用suspend()方法而停止运行的线程。
Thread的API文档中的说明是该方法恢复被挂起的(suspended)线程。该方法首先调用该线程的无参的checkAccess() 方法,这可能在当前线程上抛出SecurityException 异常,如果该线程是活着的(alive)但是被挂起(suspend),它被恢复并继续它的执行进程。
 
60、Given the following code:
1) public class Test {
2) int m, n;
3) public Test() {}
4) public Test(int a) { m=a; }
5) public static void main(String arg[]) {
6) Test t1,t2;
7) int j,k;
8) j=0; k=0;
9) t1=new Test();
10) t2=new Test(j,k);
11) }
12) }
Which line would cause one error during compilation?
A. line 3
B. line 5
C. line 6
D. line 10
(d)
题目:给出下面的代码:
在编译时哪行将导致一个错误。
第10行的声明调用一个带两个参数的Test的构造方法,而该类没有这样的构造方法。

--------------------------------------------------------------------------------------------------------------------------------
SCJP考试中的几点注意
● 深刻理解面向对象的思想
Java是一种纯粹的面向对象的程序设计语言。在正式使用Java做开发之前,必须将我们的思维方式转入一个彻底的面向对象的世界。做不到这一点,就无法体会Java语言的精髓,写不出地道的Java程序。当然,你也无法彻底理解Java中的基本概念和他们之间的联系与区别,如例题3、例题5。你可以学到Java的语法规则,却不能看到Java的灵魂。
● 对概念细节的精确把握
通过例题我们可以看到,SCJP的考察点相当细致。如例题1、2、4、7、8。所以只有对Java的概念、语法、规则了然于心,才能在考场上应对自如。
● 适量的练习
程序设计是一项实践性很强的技术。只有上机实践,才能使课本中的理论、头脑中的思想通过你的双手成为一行行代码,完成规定的目标。虽然SCJP考试不考操作与编程,但有大量的程序阅读,如例题3、4、9、10。如果你自己写过许多代码的话,这种题就是小菜一碟。
● 广泛的交流
善于交流是优秀程序员必备的技能,也是你解决疑难,提高水平的捷径。国内外有很多与Java认证相关的优秀网站和论坛,如: www.javaranch.com, www.javaunion.net等, 都是学习Java的宝库。同时,一些很棒的模考软件,如Jxam、JTest、 Javacert等,以及著名的模考题如MarcusGreen的三套题均可以找到。
无论你是个新手,还是程序设计方面的专家,你都会惊异于Sun公司Java的无穷魅力。Java带给你的并不仅仅是面向对象、开放、平台无关、易用、安全和“Write once, run anywhere”等软件开发方面的优势,更重要的一点是,它提供了一种新颖的表达思想的方式,一种全新的思维模式。随着待解决问题的规模不断膨胀,Java彻底的面向对象思想的灵活性就会凸现出来。毋庸置疑,Java是你开发大型软件时最得心应手的利器或是你转行IT的入门首选。
SCJP考试简介
● 考试方式
全英文试题,以电脑作答,在授权的Prometric考试中心参加考试
考试编号:310-025
先决条件:无
考试题型:复选、填空和拖拽匹配
题量:59
及格标准:61%
时限:120分钟
费用:1250元
● 要求具备的能力
● 使用Java编程语言创建Java应用程序和applets。
● 定义和描述垃圾搜集,安全性和Java虚拟机(JVM)。
● 描述和使用Java语言面向对象的特点。
● 开发图形用户界面(GUI)。利用Java支持的多种布局管理。
● 描述和使用Java的事件处理模式。
● 使用Java语言的鼠标输入、文本、窗口和菜单窗口部件。
● 使用Java的例外处理来控制程序执行和定义用户自己的例外事件。
● 使用Java语言先进的面向对象特点, 包括方法重载、方法覆盖、抽象类、接口、final、static和访问控制。
● 实现文件的输入/输出 (I/O)。
● 使用Java语言内在的线程模式来控制多线程。
● 使用Java 的Sockets机制进行网络通信。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
IT公司Java笔试题
我肝了一个月,给你写出了这本Java开发手册。
Java必备基础知识点(超全)
java synchronized 用法 转自水木 java版 zms的贴子
达内java面试题
ddsdcx
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服