SCJP試題六

930. What String instance method would return true when invoked like this?

a.method(b);

Where a="GROUNDhog" and b="groundHOG"?

Select the one right answer.

A. equals()

B. toLowerCase()

C. toUpperCase()

D. equalsIgnoreCase()

E. none of the above

正確答案: D

 

931. At the end of these two lines of code:

String s="hypertext";

String t=s.substring(2,5);

What does the object reference t contain? Select the one right answer.

A. "yper"

B. "ype"

C. "pert"

D. "per"

E. "perte"

正確答案: D

 

932. After these two lines of code:

String s="Dolly";

String t=s.concat("Hello");

What characters will the object reference t contain? Select the one right answer.

A. "Hello, Dolly"

B. "Dolly Hello"

C. "Hello"

D. "Dolly"

E. none of the above

正確答案: B

 

933. What is the result of invoking main() for the classes D and E?

class D {

public static void main(String[] args){

String s1=new String("hello");

String s2=new String("hello");

if(s1.equals(s2))

System.out.println("equal");

else

System.out.println("not equal")

}

}

class E {

public static void main(String[] args){

StringBuffer s1=new StringBuffer("hello");

StringBuffer s2=new StringBuffer("hello");

if(sb1.equals(sb2))

System.out.println("equal");

else

System.out.println("not equal");

}

}

Select the one right answer.

A. D: equal; E: equal

B. D: not equal; E:not equal

C. D: equal; E: not equal

D. D: not equal; E: not equal

E. nothing appears in the standard output for either class

正確答案: C

 

934. String s="Example String"; Which operation is legal?

A. s>>>=3;

B. int i=s.length();

C. s[3]="x";

D. String short_s=s.trim();

E. String t="root"+s;

正確答案: B D E

 

935. Which contains objects without ordering, duplication, or any particular lookup/retrieval mechanism?

A. Map

B. Set

C. List

D. Collection

E. Enumeration

正確答案: B

 

936. How can you use the String method indexOf() to determine which position the letter 'C' is in given this String?

String s="ABCDE";

Write a complete statement in your answer but you do not have to assign the letter your retrieve to another variable.

Fill in the blank.

正確答案:  s.indexOf('C');

 

937. What will the result be for the following block of code when it is executed?

int i=3;

int j=0;

float k=3.2F;

long m=-3;

if(Math.ceil(i)<Math.floor(k))

if(Math.abs(i)==m)

System.out.println(i);

else

System.out.println(j);

else

System.out.println(Math.abs(m)+1);

Select the one right answer.

A. 3

B. 0

C. -3

D. 4

E. none of these

正確答案: D

 

938. Which of the following will output -4.0 ?

A. System.out.println(Math.floor(-4.7));

B. System.out.println(Math.round(-4.7));

C. System.out.println(Math.ceil(-4.7));

D. System.out.println(Math.min(-4.7));

正確答案: C

 

939. What will happen if you attempt to compile and run the following code?

Integer ten=new Integer(10);

Long nine=new Long(9);

System.out.println(ten+nine);

int i=1;

System.out.println(i+ten);

Select the one right answer.

A. 19 followed by 20

B. 19 followed by 11

C. Error:Can't onvert java lang Integer

D. 10 followed by 1

正確答案: C

 

940. If you run the code below, what gets printed out?

String s=new String("Bicycle");

int iBegin=1;

char iEnd=3;

System.out.println(s.substring(Begin, iEnd));

Select the one right answer.

A. Bic

B. ic

C. icy

D. error: no method matching substring(int,char)

正確答案: B

 

941. If you wanted to find out where the position of the letter v (ie return 2) in the string s containing "Java", which of the following could you rse?

A. mid(2,s);

B. charAt(2);

C. s.indexOf('V');

D. indexOf(s,'V');

正確答案: C

 

942. Given the following code, what test would you need to put in place of the comment line?

To result in an output of

//place test here

public class Test{

public static void main(String argv[]){

Test e=new Test();

}

Test(){

String s="Java";

String s2="Java";

//place test here{

System.out.println("Equal");

}else{

System.out.println("Not equal");

}

}

}

Select the one right answer.

A. if(s==s2)

B. if(s.equals(s2))

C. if(s.equalsIgnoreCase(s2))

D. if(s.noCaseMtch(s2))

正確答案: C

 

943. You need to create a class that will store a unique object element. You do not need to sort these elements but they must be unique.

What interface might be most suitable to meet this need?

A. Set

B. List

C. Map

D. Vector

正確答案: A

 

944. Which of the following will successfully create an instance of the Vector class and add an element?

A. Vetor v=new Vector(99);

v[1]=99;

B. Vector v=new Vector();

v.addElement(99);

C. Vector v=new Vector(100);

v.addElement("99");

正確答案: D

 

945. Which most closely matches a description of a java Map?

A. A vector of arrays for a 2D geographic representation.

B. A class for containing unique array elements.

C. A class for containing unique vector elements.

D. An interface that ensures that implementing classes cannot contain duplicate keys.

正確答案: D

 

946. How does the set collection deal with duplicate elements?

A. An exception is thrown if you attempt to add an element with a duplicate value.

B. The add method returns false if you attempt to add an element with a duplicate value.

C. A set may contain elements that return duplicate values from a call to the equal's method.

D. Duplicate values will cause an error at compile time.

正確答案: B

 

947. What will happen when you attempt to compile and run the following code?

public class Test{

public static void main(String argv[]){

Test s=new Test();

}

private Test(){

String s="Marcus";

String s2=new String("Marcus");

if(s==s2){

System.out.println("we have a match");

}else{

System.out.println("Not equal");

}

}

}

Select the one right answer.

A. Compile time error caused by private constructor

B. Output of "we have a match"

C. Output of "Not equal"

D. Compile time error by attempting to compare strings using==

正確答案: C

 

948. What will be output by the following line?

System.out.println(Math.floor(-2.1));

A. -2

B. 2.0

C. -3

D. -3.0

正確答案: D

 

949. Which of the following statements are true?

A. At the root of the collection hierarchy is a class called Collection.

B. The collection interface contains a method called enumerator.

C. The interator method returns an instance of the Vector class.

D. The set interface is designed for unique elements.

正確答案: D

 

950. Which of the following methods are members of the Vector class and allow you to input a new element?

A. addElement

B. insert

C. append

D. addItem

正確答案: A

 

951. Which of the following are valid statements?

A. public class MyCalc extends Math

B. Math.max(s);

C. Math.round(9.99,1);

D. Math.mod(4,10);

E. None of these

正確答案: E

 

952. Given the following declaration?

Integer i=new Integer(99);

How can you now set the value of i to 10 ?

A. i=10;

B. i.setValue(10);

C. i.parseInt(10);

D. none of the above

正確答案: D

 

953. Given the following class?

public class Test{

public static void main(String argv[]){

int i=0;

//Here

}

}

Which of the following lines if placed after the comment? //Here will print out 0.

A. System.out.println(i++);

B. System.out.println(i+'0');

C. System.out.println(i);

D. System.out.println(i--);

正確答案: A C D

 

954. Which of the following are examples of immutable classes, select all correct answer(s) ?

A. String

B. StringBuffer

C. Double

D. Integer

正確答案: A C D

 

955. Which of the following statements would return false? if given the following statements.

String s=new String("New year");

String s1=new String("new Year");

Select the one right answer.

A. s==s1

B. s.equals(s1);

C. s=s1;

D. None of the above

正確答案: A B

 

956. What is the result when you compile and run the following code?

public class Test{

public static void main(String args[]){

int x=0;

for (int i=; i<10; i++){

x=new Math(i);

System.out.println(x);

}

}

}

Select the one right answer.

A. Prints 0 to 9 in sequence

B. No output

C. Runtime error

D. Compile time error

正確答案: D

 

957. Which of the following casses will throw "NumberFormatException"?

A. Double

B. Boolean

C. Integer

D. Byte

正確答案: A C D

 

958. What is the result when you compile and run the following code?

import java.util.*;

public class MyVector{

public Vector myVector(){

Vector v=new Vector();

return v.addElement("Adding element to vector");

}

public static void main(String[] args){

Test mv=new Test();

System.out.println(mv.myVector());

}

}

Select the one right answer.

A. Prints Adding element to vector

B. Compile time error

C. Runtime error

D. Compiles and runs successfully

正確答案: B

 

959. What are possible ways to implement linkedList class?

A. As a HashMap

B. As a Queue

C. As a TreeSet

D. As a Stack

正確答案: B D

 

960. What is the result when you try to compile and run the following ode?

public class Test {

public static void main(String args[]){

String s="HelloWorld";

if ((s !=null)&& (s.length()>6))

System.out.println("The value of s is "+s);

}

}

Select the one right answer.

A. Compile time error

B. Runtime error

C. No output is printed

D. The value of s is HelloWorld will be printed on the screen

正確答案: D

 

961. Which of the following statements are true about the fragment below?

import java.lang.Math;

public class Test{

pubilc static void main(String args[]){

Math m = new Math();

System.out.println(m.abs(2.6);

}

}

Select the one right answer.

A. Compiler fails at line 1

B. Compiler fails at line 3

C. Compiler fails at the time of Math class instantiation

D. Compiler succeeds.

正確答案: C

 

962. What will be the output of the following line?

public class Test{

public static void main(String args[]){

System.out.println(Math.floor(145.1));

System.out.println(Math.floor(-145.4));

}

}

Select the one right answer.

A. 145.0 followed by -145.0

B. 150.0 followed by -150.0

C. 145.1 followed by -145.4

正確答案: A

 

963. Which of the following implement clear notion of one item follows another(order)?

A. List

B. Set

C. Map

D. Vector

正確答案: A

 

964. Collection interface iterator method returns Iterator(lide Enumerator), through you can traverse a collection from start to finish and safely remove elements.

A. true

B. false

正確答案: A

 

965. Which of the following places no constraints on the type of elements, order of elements. or repetition of elements with in the collection?

A. List

B. Collection

C. Map

D. set

正確答案: B

 

966. Which of the following gives Stack and Queue functionality?

A. Map

B. Vector

C. List

D. Set

正確答案: C

 

967. Which are not Java primitive types?

A. short

B. Boolean

C. unit

D. float

正確答案: B C

 

968. What is the output of following if the return value is "the value 0 if the argument string is equal to this string; a value less than 0 if this string is lexicographically less than the string argument; and a value greater than 0 if this string is lexicographically greater than the string argument"(Assuming written inside main)

String s5="AMIT";

String s6="amit";

System.out.println(s5.ompareTo(s6));

System.out.println(s6.ompareTo(s5));

System.out.println(s6.ompareTo(s6));

Select the one right answer.

A. -32

32

0

B. 32

32

0

C. 32

-32

0

D. 0

0

0

正確答案: A

 

969. What is the output(Assuming written inside main)?

String s1=new String("amit");

String s2=new String("'m','i');

s1.concat("Poddar");

System.out.println(s1);

System.out.println((s1+s2).charAt(5));

Select the one right answer.

A. Compile error

B. amitPoddar

o

C. amitPoddar

i

D. amit

i

正確答案: D

 

970. What is the output(Assuming written inside main)?

String s1=new String("amit");

System.out.println(s1.replace('m','r'));

System.out.println(s1);

String s3="arit";

String s4="arit";

String s2=s1.replace('m','r');

System.out.println(s2==s3);

System.out.println(s3==s4);

Select the one right answer.

A. aret

amit

false

true

B. arit

arit

false

true

C. amil

amit

false

true

D. arit

amit

true

true

正確答案: A

 

971. Which one does not extend java.lang.Number?

A. Integer

B. Boolean

C. Character

D. Long

E. Short

正確答案: B C

 

972. Which one does not have a valueOf(String)method?

A. Integer

B. Boolean

C. Character

D. Long

E. Short

正確答案: C

 

973. What will be the output of following?

{

double d1=-o.5d;

System.out.println("Cell for d1 "+Math.ceil(d1));

System.out.println("Floor for d1 "+Math.floor(d1));

}

Select the one right answer.

A. Ceil for d1 0

Floor for d1 -10;

B. Ceil for d1 -1.0

Floor for d1 0.0;

C. Ceil for d1 0.0

Floor for d1 -1.0;

D. Ceil for d1 -0.0

Floor for d1 -1.0;

正確答案: D

 

974. What is the output of following?

{

float f4==-5.5f;

float f5==5.5f;

float f6==-5.49f;

float f7==5.49f;

System.out.println("Round f4 is"+Math round (f4));

System.out.println("Round f5 is"+Math round (f5));

System.out.println("Round f6 is"+Math round (f6));

System.out.println("Round f7 is"+Math round (f7));

}

Select the one right answer.

A. Round f4 is -6

Round f5 is 6

Round f6 is -5

Round f7 is 5

B. Round f4 is -5

Round f5 is 6

Round f6 is -5

Round f7 is 5

正確答案: B

 

975. Given Integer.MIN_VALUE=-2147483648; Integer.MAX_VALUE=2147483647?

What is the output of following?

{

float f4=Integer.MIN_VALUE;

float f5=Integer.MIN_VALUE;

float f7=-2147483655f;

System.out.println("Round f4 is "+Math.round(f4));

System.out.println("Round f5 is "+Math.round(f5));

System.out.println("Round f7 is "+Math.round(f7));

}

Select the one right answer.

A. Round f4 is -2147483648

Round f5 is 2147483647

Round f7 is -2147483648

B. Round f4 is -2147483648

Round f5 is 2147483647

Round f7 is -214748365

正確答案: A

 

976. What is the output of following?

1  Boolean b1 =new Boolean("TRUE");

2  Boolean b2 =new Boolean("true");

3  Boolean b3 =new Boolean("JUNK");

4  System.out.println(""+b1+b2+b3);

Select the one right answer.

A. Compiler error

B. RunTime error

C. truetruefalse

D. truetruetrue

正確答案: C

 

977. What is the output of following?

1  Boolean b1 = new Boolean("TRUE");

2  Boolean b2 = new Boolean("true");

3  Boolean b3 = new Boolean("JUNK");

4  System.out.println(b1+b2+b3);

Select the one right answer.

A. Compile time error

B. Run time error

C. truetruefalse

D. truetruetrue

正確答案: A

 

978. What is the output?

{

Float f1=new Float("4.4e99f");

Float f2=new Float("-4.4e99f");

Double d1=new Double("4.4e99");

System.out.println(f1);

System.out.println(f2);

System.out.println(d1);

}

Select the one right answer.

A. Runtime error

B. Infinity

-Infinity

4.4e99

C. Infinity

-Infinity

Infinity

D. 4.4E99

-4.4E99

4.4E99

正確答案: B

 

979. Which of the following wrapper classes cannot take a "String" in constructor?

A. Boolean

B. Integer

C. Long

D. Character

E. Byte

F. Short

正確答案: D

 

980. What is the output of the following code?

1:  String str = "Welcome";

2:

3:  str.concat("to java!");

4:

5:  System.out.println(str);

Select the one right answer.

A. Strings are immutable, compilation error at line 3.

B. Strings are immutable, runtime exception at line 3.

C. Prints "Welcome".

D. Prints "Welcome to Java!".

正確答案: C

 

本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/wangjun_pfc/archive/2007/10/13/1823177.aspx

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章