SCJP模拟试题[2](2)
添加时间: 2007-9-23 2:26:18 作者: JAVA题库 阅读次数:112 来源: http://www.d9soft.com
2. public void init(){
3. sz=10;
4. String tmp=getParameter("size");
5. if(tmp!=null X tmp.equals("BIG")) sz=20;
6. }
a). Replace X with '&'
b). Replace X with '&&'
c). Replace X with ''
d). Replace X with ''
-------------------------------------
Question 22:
Which of the following statements results in C containing the special "Not a Number" value?
a. float C=1234.0F/0.0F;
b. float C=(float)java.lang.Math.sqrt(-1.0);
c. float C=Float.MIN_VALUE/Float.MAX_VALUE;
--------------------------------------------
Question 23: [Check all correct answers]
You are writing a java class in a file named "MyClass.java", this class must be accessible by all classes in a large project. Which of the following would be correct class declarations?
a. private class MyClass extends Object
b. class myclass extends Object
c. public class MyClass
d. public class MyClass extends Object
------------------------------------------
Question 24: [Check all correct answers]
Once created, some Java objects are "immutable", meaning they can not have their contents changed. Which of the following classed produce immutable objects?
a. java.lang.Double
b. java.lang.StringBuffer
c. java.lang.Boolean
d. java.lang.Math
---------------------------------------
Question 25:
Given the following class definitions:
1. class BaseWidget extends Object{
2. String name="BaseWidget";
3. void speak(){System.out.println("I am a "+name);}
4. }
5. class TypeAWidget extends BaseWidget{
6. TypeAWidget(){name="TypeA";}
7. }
Which of the following code fragments will compile and execute without error?
a. Object A=new BaseWidget();
A.speak();
B.speak();
c. TypeAWidget C=new BaseWidget();
C.speak();
------------------------------------------
Question 26: [Check all correct answers]
Pick the keyword(s) which can NOT be used as modifiers in declaration of a method in a Java class.
a) private
b) friend
c) protected
d) static
e) synchronized
f) generic
-----------------------------------------
Question 27: [Check all correct answers]
Which of the following would be an illegal identifier for a Java method?
a) do_it_now
b) _Substitute
c) 9thMethod
d) $addMoney
e) %getPath
-------------------------------------------
Question 28:
Given the following code for the Demo class:
public class Demo{
private int[] count;
public Demo(){ count=new int[10];}
public void setCount(int ct,int n){ count[n]=ct;}
public void showCount(int n){
System.out.println("Count is "+count[n]);
}
public int getCount(int n){ return count[n];}
}
what would be the result of calling the showCount method with a parameter of 9 immediately after creating an instance of Demo?
a) A NullPointerException would be thrown, halting the program.
b) Standard output would show "Count is 0".
c) An ArrayIndexOutOfBoundsException would be thrown, halting the program.
d) Standard output would show "Count is null".
-------------------------------
Question 29:
What happens when we attempt to compile and run the following code?
1. public class Logic{
2. static long sixteen=0x0010;
3. static public void main(String args[]){
4. long N=sixteen>>4:
5. System.out.println("N= "+N);
6. }
7. }
a) The compiler will object to line 4 combining a long with an int.
b) The program will compile and run, producing the output "N=0".
c) The program will compile and run, producing the output "N=1".
d) A rutime exception will be thrown.
-------------------------------------
Question 30:
What will happen on trying to compile and run the following application?
1. public class Example{
2. public Boolean flags[]=new Boolean[4];
3. public static void main(String[] args){
4. Example E=new Example();
5. System.out.println("Flag 1 is "+E.flags[1]);
6. }
7. }
a) The text "Flag 1 is true" will be written to standard output.
b) The text "Flag 1 is false" will be written to standard output.
c) The text "Flag 1 is null" will be written to standard output.
d) The compiler will object to line 2.
--------------------------------------------
Question 31: [Check all correct answers]
Which of the following code fragments are legal Java code?
a) String A="abcdefg";
A-="cde";
b) String A="abcdefg";
A+="cde";
c) Integer J=new Integer(27);
J-=7;
d) Integer J=new Integer(27);
J--;
----------------------------------------------
Question 32:
Given the following code for the code for Demo class, where "XXXX" represents an access modifier:
public class Demo extends Base{
XXXX String userName;
public void setName(String s){ userName=s;}
public void showName(){
System.out.println("Name is "+userName):
}
public String getName(){ return userName; }
}
Select the modifier which would be used to give only classes in the default package or classes derived from Demo, direct access to the userName String variable.
a) public
b) blank (ie - the line would read "String userName :")
c) protected
d) private
---------------------------------------------
Question 33:
Given the following method in an application:
1. public String setFiletype(String fname){
2. int p=fname.indexOf('.');
3. if(p>0) fname=fname.substring(0,p);
4. fname+=".TXT";
5. return fname;
6. }
and given that another part of the class has a the following code:
7. String TheFile="Program.java";
8. File F=new File(setFileType(TheFile));
9. System.out.println("Created "+TheFile);
What will be printed by the statement in line 9?
a) "Created Program.java"
b) "Created Program.txt"
c) "Created Program.java.txt"
----------------------------------
Question 34:
What happens on trying to compile and run the following code?
1. public class EqualsTest{
2. public static void main(String args[]){
3. byte A=(byte)4096;
上一篇文章: SCJP模拟试题[2](1) 下一篇文章: SCJP模拟试题[2](3)

](/d9soft/images/logo_1.gif)