SCJP模拟试题[2](3)
添加时间: 2007-9-23 2:30:12 作者: JAVA题库 阅读次数:173 来源: http://www.d9soft.com
4. if(A==4096)System.out.println("Equal");
5. else System.out.println("Not Equal");
6. }
7. }
a) The compiler objects to the loss of accurcy in the cast in line 3.
b) The program compiles and prints "Not Equal".
c) The program compiles and prints "Equal".
---------------------------------------------
Question 35:
What happens on trying to compile and run the following code?
1. public class EqualsTest{
2. public static void main(String args[]){
3. Long LA=new Long(7);
4. Long LB=new Long(7);
5. if(LA==LB) System.out.println("Equal");
6. else System.out.println("Not Equal");
7. }
8. }
a) The program compiles but throws a runtime exception in line 5.
b) The program compiles and prints "Not Equal";
c) The program compiles and prints "Equal".
-----------------------------------------------
Question 36: [Check all correct answers]
Given the following code for the Demo class:
public class Demo extends Base{
private int count;
public Demo(){
System.out.println("A Demo object has been created");
}
protected void addOne() {count++; }
}
Which of the following statements about the "count" variable is correct?
a) When a new Demo object is created, the value of count is zero.
b) When a new Demo object is created, the value of count is undefined.
c) An object of the Base class can have methods which modify the count variable.
d) The only way the count variable can be modified is by calling the addOne method.
-------------------------------------
Question 37: [Check all correct answers]
Which of the following statements will cause a compiler error.
a) float F=4096.0;
b) double D=4096.0;
c) byte B=4096;
d) char C=4096;
--------------------------------------
Question 38:
In the following method, which may be called with any kind of Object, we want to "short circuit" the logical test in line 2 if the object is not a Long. Which logical operator should replace the X in line 2 to accomplish this?
1. long Test(Object ob){
2. if(Ob instanceof Long X ((Long)Ob).longValue()>999){
3. return((Long)Ob).longValue();
4. }
5. return -1L;
6. }
a) Replace 'X' with '&&'.
b) Replace 'X' with ''.
c) Replace 'X' with '&'.
d) Replace 'X' with ''.
---------------------------------------
Question 39:
Which of the following statements is the correct form fro determining whether the float primitive X has the specail "Not a Number" value?
a) if(X instanceof Float.NaN)
b) if(X==Float.NaN)
c) if(Float.isNaN(X))
--------------------------------------
Question 40:
Which of the following are organizing principles of Java 's "javadoc" format documentation for a given class?
a) Relative frequency of use of the various methods.
b) Lists of methods in a class in alphabetic order.
c) Separate listing of private, protected and public methods in a calss.
--------------------------------------
Question 41:
The following program is compiled and then run with this command line:
java Demo alpha beta gamma
public class Demo{
public static void main(String args[]){
int n=3;
System.out.println("The word is "+args[n]);
}
}
What happens?
a) "The word is beta" is written to standard output.
b) "The word is gamma" is written to standard output.
c) The runtime system reports an ArrayIndexOutOfBoundsException in the main method.
d) The runtime system reports a NullPointerException in the main method.
-----------------------------------
Question 42:
What will be the result of running the following method with an input of 67?
public int MaskOff(int N){
return N^3;
}
a) The method will return 3.
b) The method will return 64.
c) The method will return 67.
d) The method will return 0.
-------------------------------
Question 43:
What happens on trying to compile and run the following code?
public class EqualsTest{
public static void main(String args[]){
char A='u0005';
if(A==0x0005L) System.out.println("Equal");
else System.out.println("Not Equal");
}
}
a) The compiler reports "Invalid character in input" in line 3.
b) The program compiles and prints "Not Equal".
c) The program compiles and prints "Equal".
Q. 55
With which I/O operation can we append, update a file?
a) RandomAccessFile()
上一篇文章: SCJP模拟试题[2](2) 下一篇文章: SCJP Mock Exam 1(1)

](/d9soft/images/logo_1.gif)