阿摩:千點萬點,不如名師指點
2
(27 秒)
模式:試卷模式
試卷測驗 - 104 年 - SCJP 151-200#99330
繼續測驗
再次測驗 下載 下載收錄
1(B).

151. Given that the current directory is empty, and that the user has read and write privileges to the current directory, and the following:
   60c81e2872772.jpg Which statement is true?
(A) Compilation fails.
(B) Nothing is added to the file system.
(C) Only a new file is created on the file system.
(D) Only a new directory is created on the file system.
(E) Both a new file and a new directory are created on the file system.



2( ).
X


152. Which three statements concerning the use of the java.io.Serializable interface are true? (Choose three.)
(A) Objects from classes that use aggregation cannot be serialized.
(B) An object serialized on one JVM can be successfully deserialized on a different JVM.
(C) The values in fields with the volatile modifier will NOT survive serialization and deserialization.
(D) The values in fields with the transient modifier will NOT survive serialization and deserialization.
(E) It is legal to serialize an object of a type that has a supertype that does NOT implement java.io.Serializable.


3( ).
X


154. Given that c is a reference to a valid java.io.Console object, which two code fragments read a line of text from the console? (Choose two.)
(A) String s = c.readLine();
(B) char[] c = c.readLine();
(C) String s = c.readConsole();
(D) char[] c = c.readConsole();
(E) String s = c.readLine("%s", "name "); 


4( ).
X


157. Given that c is a reference to a valid java.io.Console object, and: 
11. String pw = c.readPassword("%s", "pw: "); 
12. System.out.println("got " + pw); 
13. String name = c.readLine("%s", "name: "); 
14. System.out.println(" got", name); 
If the user types fido when prompted for a password, and then responds bob when prompted for a name, what is the result?
(A) pw: got fido name: bob got bob
(B) pw: fido got fido name: bob got bob
(C) pw: got fido name: bob got bob
(D) pw: fido got lido name: bob got bob
(E) Compilation fails. 


5( ).
X


158. Given a vaid DateFormat object named df, and 
16. Date d = new Date(0L);
 17. String ds = "December 15, 2004"; 
18. //insert code here
 What updates d's value with the date represented by ds?
(A) 18. d = df.parse(ds);
(B) 18. d = df.getDate(ds); 
(C) 60c81fec734bd.jpg
(D) 60c82013ebf4e.jpg


6( ).
X


159. Given: 
11. double input = 314159.26; 
12. NumberFormat nf = NumberFormat.getInstance(Locale.ITALIAN); 
13. String b;
 14. //insert code here Which code, inserted at line 14, sets the value of b to 314.159,26?
(A) b = nf.parse(input);
(B) b = nf.format(input);
(C) b = nf.equals(input);
(D) b = nf.parseObject(input);


7( ).
X


160. Given: 
22. StringBuilder sb1 = new StringBuilder("123"); 
23. String s1 = "123";
 24. //insert code here 
25. System.out.println(sb1 + " " + s1);
 Which code fragment, inserted at line 24, outputs "123abc 123abc"?
(A) sb1.append("abc"); s1.append("abc");
(B) sb1.append("abc"); s1.concat("abc");
(C) sb1.concat("abc"); s1.append("abc");
(D) sb1.concat("abc"); s1.concat("abc");
(E) sb1.append("abc"); s1 = s1.concat("abc"); 


8( ).
X


161. Given:
 1. public class Boxer1{ 
2. Integer i 
3. int x; 
4. public Boxer1(int y){ 
5. x = i + y; 
6. System.out.println(x); 
7. }
 8. public static void main(String[] args){ 
9. new Boxer1(new Integer(4)); 
10. } 
11. } What is the result?
(A) The value "4" is printed at the command line.
(B) Compilation fails because of an error in line 5.
(C) Compilation fails because of an error in line 9.
(D) A NullPointerException occurs at runtime.
(E) A NumberFormatException occurs at runtime.


9( ).
X


162. Given: 
11. public static void main(String[] args){ 
12. Integer i = new Integer(1) + new Integer(2);
 13. switch(i){ 
14. case 3: System.out.println("three"); break; 
15. default: System.out.println("other"); break; 
16. } 
17. } 
What is the result?
(A) three
(B) other
(C) An exception is thrown at runtime.
(D) Compilation fails because of an error on line 12.
(E) Compilation fails because of an error on line 13. 


10( ).
X


163. 32 Given: 
1. public class TestString3{ 
2. public static void main(String[] args){
 3. //insert code here 
5. System.out.println(s); 
6. } 
7. } Which two code fragments, inserted independently at line 3, generate the output 4247? (choose two.)
(A) String s = "123456789"; s = (s - "123").replace(1, 3, "24") - "89";
(B) StringBuffer s = new StringBuffer("123456789"); s.delete(0, 3).replace(1, 3, "24").delete(4, 6);
(C) StringBuffer s = new StringBuffer("123456789"); s.substring(3, 6).delete(1, 3).insert(1, "24");
(D) StringBuilder s = new StringBuilder("123456789"); s.substring(3, 6).delete(1, 2).insert(1, "24");
(E) StringBuilder s = new StringBuilder("123456789"); s.delete(0, 3).delete(1, 3).delete(2, 5).insert(1, "24");


11( ).
X


164. Given: 
1. d is a valid, non-null Date object 
2. df is a valid, non-null DateFormat object set to the current locale
 What outputs the current locale's country name and the appropriate version of d's date?
(A) Locale loc = Locale.getLocale(); System.out.println(loc.getDisplayCountry() + " " + df.format(d));
(B) Locale loc = Locale.getDefault(); System.out.println(loc.getDisplayCountry() + " " + df.format(d));
(C) Locale loc = Locale.getLocale(); System.out.println(loc.getDisplayCountry() + " " + df.setDateFormat(d));
(D) Locale loc = Locale.getDefault(); System.out.println(loc.getDisplayCountry() + " " + df.setDateFormat(d));


12( ).
X


165. Given: 
5. import java.util.Date;
 6. import java.text.DateFormat; 
21. DateFormat df; 
22. Date date = new Date();
 23. //insert code here 
24. String s = df.format(date); 
Which code fragment, inserted at line 23, allows the code to compile?
(A) df = new DateFormat();
(B) df = Date.getFormat();
(C) df = date.getFormat();
(D) df = DateFormat.getFormat();
(E) df = DateFormat.getInstance();


13( ).
X


166. Given: 
1. public class BuildStuff{ 
2. public static void main(String[] args){ 
3. Boolean test = new Boolean(true); 
4. Integer x = 343; 
5. Integer y = new BuildStuff().go(test, x); 
6. System.out.println(y);
 7. } 
8. int go(Boolean b, int i){ 
9. if(b) return (i/7);
 10. return (i/49); 
11. } 
12. } 
What is the result?
(A) 7
(B) 49
(C) 343
(D) Compilation fails.
(E) An exception is thrown at runtime.


14( ).
X


167. Given: 
11. String test = "Test A. Test B.Test C."; 
12. //insert code here 34 
 13. String[] result = test.split(regex); 
Which regular expression, inserted at line 12, correctly splits test into "Test A", "Test B", and "Test C"?
(A) String regex = "";
(B) String regex = " ";
(C) String regex = ".*";
(D) String regex = "s";
(E) String regex = ".s*";


15( ).
X


168. Given:
 11. public void testIfA(){ 
12. if(testIfB("True")){ 
13. System.out.println("True");
 14. }else{ 
15. System.out.println("Not true"); 
16. } 
17. } 
18. public Boolean testIfB(String str){ 
19. return Boolean.valueOf(str); 
20. } 
What is the result when method testIfA is invoked?
(A) True
(B) Not true
(C) An exception is thrown at runtime.
(D) Compilation fails because of an error at line 12.
(E) Compilation fails because of an error at line 19.


16( ).
X


170. Given: 
12. String csv = "Sue,5,true,3"; 
13. Scanner scanner = new Scanner(csv); 
14. scanner.useDelimiter(","); 
15. int age = scanner.nextInt(),
 What is the result?
(A) Compilation fails.
(B) After line 15, the value of age is 5.
(C) After line 15, the value of age is 3.
(D) An exception is thrown at runtime.


17( ).
X


171. Given:
 11. String test = "a1b2c3"; 
12. String[] tokens = test.split("d"); 
13. for(String s : tokens) System.out.print(s + " ");
 What is the result?
(A) a b c
(B) 1 2 3
(C) a1b2c3
(D) a1 b2 c3
(E) Compilation fails.


18( ).
X


172. Given: 
33. Date d = new Date(0);
 34. String ds = "December 15, 2004"; 
35. //insert code here 
36. try{ 
37. d = df.parse(ds); 
38. } 
39. catch(ParseException e){ 
40. System.out.println("Unable to parse " + ds); 
41. } 
42. //insert code here too
 What creates the appropriate DateFormat object and adds a day to the Date object?
(A) 35. DateFormat df = DateFormat.getDateFormat(); 42. d.setTime((60 * 60 * 24) + d.getTime();
(B) 35. DateFormat df = DateFormat.getDateInstance(); 42. d.setTime((1000 * 60 * 60 * 24) + d.getTime());
(C) 35. DateFormat df = DateFormat.getDateFormat(); 42. d.setLocalTime((1000 * 60 * 60 * 24) + d.getLocalTime());
(D) 35. DateFormat df = DateFormat.getDateInstance(); 42. d.setLocalTime((60 * 60 * 24) + d.getLocalTime());


19( ).
X


173. Given: 
11. public class Yikes{ 
12. 
13. public static void go(Long n){System.out.print("Long ");}
 14. public static void go(Short n){System. outprint("Short ");} 
15. public static void go(int n){System.out.print("int ");} 
16. public static void main(String[] args){
 17. short y = 6;
 18. long z = 7; 
19. go(y); 
20. go(z);
 21. }
 22. }
 What is the result?
(A) int Long
(B) Short Long
(C) Compilation fails.
(D) An exception is thrown at runtime.


20( ).
X


174. Given:
 12. Date date = new Date(); 
13. df.setLocale(Locale.ITALY); 
14. String s = df.format(date); 
The variable df is an object of type DateFormat that has been initialized in line 11. What is the result if this code is run on December 14, 2000?
(A) The value of s is 14-dic-2000.
(B) The value of s is Dec 14, 2000.
(C) An exception is thrown at runtime.
(D) Compilation fails because of an error in line 13.


21( ).
X


175. Which two scenarios are NOT safe to replace a StringBuffer object with a StringBuilder object? (Choose two.)
(A) When using versions of Java technology earlier than 5.0.
(B) When sharing a StringBuffer among multiple threads.
(C) When using the java.io class StringBufferInputStream.
(D) When you plan to reuse the StringBuffer to build more than one string.
(E) Enitiation of separate design processes to the separation of users


22( ).
X


177. Given: 
11. String test = "This is a test"; 
12. String[] tokens = test.split("s"); 
13. System.out.println(tokens.length); 
What is the result?
(A) 0
(B) 1
(C) 4
(D) Compilation fails.
(E) An exception is thrown at runtime.


23( ).
X


178. Given:
 1. public class Target{
 2. private int i = 0;
 3. public int addOne(){
 4. return ++i; 
5. }
 6. }
 And: 
1. public class Client{ 
2. public static void main(String[] args){
 3. System.out.println(new Target().addOne()); 
4. } 
5. } Which change can you make to Target without affecting Client?
(A) Line 4 of class Target can be changed to return i++;
(B) Line 2 of class Target can be changed to private int i = 1;
(C) Line 3 of class Target can be changed to private int addOne(){
(D) Line 2 of class Target can be changed to private Integer i = 0;


24( ).
X


185. Given:
 1. public class Person{ 
2. private String name; 
 3. public Person(String name){this.name = name;} 
4. public boolean equals(Person p){ 
5. return p.name.equals(this.name); 
6. } 
7. }
 Which statement is true?
(A) The equals method does NOT properly override the Object.equals method.
(B) Compilation fails because the private attribute p.name cannot be accessed in line 5.
(C) To work correctly with hash-based data structures, this class must also implement the hashCode method.
(D) When adding Person objects to a java.util.Set collection, the equals method in line 4 will prevent duplicates.


25( ).
X


186. Which two statements are true about the hashCode method? (Choose two.)
(A) The hashCode method for a given class can be used to test for object equality and object inequality for that class.
(B) The hashCode method is used by the java.util.SortedSet collection class to order the elements within that set.
(C) The hashCode method for a given class can be used to test for object inequality, but NOT object equality, for that class.
(D) The only important characteristic of the values returned by a hashCode method is that the distribution of values must follow a Gaussian distribution.
(E) The hashCode method is used by the java.util.HashSet collection class to group the elements within that set into hash buckets for swift retrieval.


26( ).
X


187. Given: 
1. public class Score implements Comparable<Score>{
 2. private int wins, losses; 
3. public Score(int w, int l){wins = w; losses = l;} 
4. public int getWins(){return wins;} 
5. public int getLosses(){return losses;} 
6. public String toString(){ 
7. return "<" + wins + "," + losses + ">"; 
8. } 
9. //insert code here
 10. } 
Which method will complete this class?
(A) public int compareTo(Object o){/* more code here */}
(B) public int compareTo(Score other){/* more code here */}
(C) public int compare(Score s1, Score s2){/* more code here */}
(D) public int compare(Object o1, Object o2){/* more code here */}


27( ).
X


189. Given: 
23. Object[] myObjects = { 
24. new Integer(12), 
25. new String("foo"), 
26. new Integer(5), 
27. new Boolean(true) 
28. }; 
29. Arrays.sort(myObjects); 
30. for(int i=0; i<myObjects.length; i++){ 
31. System.out.print(myObjects[i].toString()); 
32. System.out.print(" "); 
33. } 
What is the result?
(A) Compilation fails due to an error in line 23.
(B) Compilation fails due to an error in line 29.
(C) A ClassCastException occurs in line 29.
(D) A ClassCastException occurs in line 31.
(E) The value of all four objects prints in natural order.


28( ).
X


190. Given: 
1. import java.util.*; 
2. public class WrappedString{ 
3. private String s;
 4. public WrappedString(String s){this.s = s;} 
5. public static void main(String[] args){
 6. HashSet<Object> hs = new HashSet<Object>(); 
7. WrappedString ws1 = new WrappedString("aardvark");
 8. WrappedString ws2 = new WrappedString("aardvark"); 
9. String s1 = new String("aardvark"); 
10. String s2 = new String("aardvark");
11. hs.add(ws1); hs.add(ws2); hs.add(s1); hs.add(s2); 
12. System.out.println(hs.size()); }} 
What is the result?
(A) 0
(B) 1
(C) 2
(D) 3
(E) 4


29( ).
X


192. Given: 
3. import java.util.*;
 4. public class G1{ 
5. public void takeList(List<? extends String> list){ 
6. //insert code here 
7. } 
8. }
 Which three code fragments, inserted independently at line 6, will compile? (Choose three.)
(A) list.add("foo");
(B) Object o = list;
(C) String s = list.get(0);
(D) list = new ArrayList<String>();
(E) list = new ArrayList<Object>();


30( ).
X


193. Given that the elements of a PriorityQueue are ordered according to natural ordering, and: 
2. import java.util.*; 
3. public class GetInLine{ 
4. public static void main(String[] args){
 5. PriorityQueue<String> pq = new PriorityQueue<String>(); 
6. pq.add("banana"); 
7. pq.add("pear"); 
8. pq.add("apple"); 
9. System.out.println(pq.poll() + " " + pq.peek()); 
10. } 
11. } 
What is the result?
(A) apple pear
(B) banana pear
(C) apple apple
(D) apple banana
(E) banana banana


31( ).
X


194. Given: 
       enum Example{ONE, TWO, THREE} 
Which statement is true?
(A) The expressions (ONE == ONE) and ONE .equals(ONE) are both guaranteed to be true.
(B) The expression (ONE < TWO) is guaranteed to be true and ONE.compareTo(TWO) is guaranteed to be less than one.
(C) The Example values cannot be used in a raw javautil.HashMap; instead, the programmer must use a java.util.EnumMap.
(D) The Example values can be used in a java.util.SortedSet, but the set will NOT be sorted because enumerated types do NOT implement java.lang.Comparable.


32( ).
X


195. Given: 
3. import java.util.*; 
4. public class Mapit{ 
5. public static void main(String[] args){ 
6. Set<Integer> set = new HashSet<Integer>();
 7. Integer i1 = 45; 
8. Integer i2 = 46; 
9. set.add(i1);
 10. set.add(i1); 
11. set.add(i2); System.out.print(set.size() + " ");
 12. set.remove(i1); System.out.print(set.size() + " ");
 13. i2 = 47;
 14. set.remove(i2); System.out.print(set.size() + " "); 
15. }
 16. } What is the result?
(A) 2 1 0
(B) 2 1 1
(C) 3 2 1
(D) 3 2 2
(E) Compilation fails.


33( ).
X


196. Given: 
34. HashMap props = new HashMap(); 
35. props.put("key45", "some value"); 
36. props.put("keyl2", "some other value"); 
37. props.put("key39", "yet another value");
 38. Set s = props.keySet(); 
39. //insert code here 
What inserted at line 39, will sort the keys in the props HashMap?
(A) Arrays.sort(s);
(B) s = new TreeSet(s);
(C) Collections.sort(s);
(D) s = new SortedSet(s);


34( ).
X


197. Given: 
11. public static Collection get(){ 
12. Collection sorted = new LinkedList(); 
13. sorted.add("B"); sorted.add("C"); sorted.add("A"); 
14. return sorted; 
15. }
 16. public static void main(String[] args){ 
17. for(Object obj : get()){ 
18. System.out.print(obj + ", "); 
19. } 
20. } 
What is the result?
(A) A, B, C,
(B) B, C, A,
(C) Compilation fails.
(D) The code runs with no output
(E) An exception is thrown at runtime.


35( ).
X


198. Given: 
11. public static Iterator reverse(List list){ 
12. Collections.reverse(list); 
13. return list.iterator();
 14. }  
15. public static void main(String[] args){ 
16. List list= new ArrayList(); 
17. list.add("1"); list.add("2"); list.add("3");
 18. for(Object obj : reverse(list)) 
19. System.out.print(obj + ", ");
 20. } 
What is the result?
(A) 3, 2, 1,
(B) 1, 2, 3,
(C) Compilation fails.
(D) The code runs with no output.
(E) An exception is thrown at runtime.


36( ).
X


200. Given: 
11. public class Person{ 
12. private String name; 
13. public Person(String name){ 
14. this.name = name; 
 15. } 
16. public boolean equals(Object o){ 
17. if(!(o instanceof Person)) return false; 
18. Person p = (Person)o; 
19. return p.name.equals(this.name); 
20. }
 21. } Which statement is true?
(A) Compilation fails because the hashCode method is not overridden.
(B) A HashSet could contain multiple Person objects with the same name.
(C) All Person objects will have the same hash code because the hashCode method is not overridden.
(D) If a HashSet contains more than one Person object with name="Fred", then removing another Person, also with name="Fred", will remove them all.


【非選題】

153. Chain these constructors to create objects to read from a file named "in" and to write to a file named "out".60c81e7494a46.jpg60c81e9e48b9c.jpg



【非選題】

155. The doesFileExist method takes an array of directory names representing a path from the root filesystem and a file name. The method returns true if the file exists, false if it does not. Place the code fragments in position to complete this method.60c81ee4c82e3.jpg60c81f089075a.jpg



【非選題】

156. Place the code fragments into position to use a BufferedReader to read in an entire text file.60c81f4ae4e01.jpg



【非選題】
169. Given:
 12. NumberFormat nf = NumberFormat.getInstance();
 13. nf.setMaximumFractionDigits(4);
 14. nf.setMinimumFractionDigits(2); 
15. String a = nf.format(3.1415926);
 16. String b = nf.format(2); 
Which two statements are true about The result if the default locale is Locale.US? (Choose two.)
(A) The value of b is 2.
(B) The value of a is 3.14.
(C) The value of b is 2.00.
(D) The value of a is 3.141.
(E) The value of a is 3.1415. (F) The value of a is 3.1416. (G)The value of b is 2.0000.


【非選題】

176. Place the code fragments into position to produce the output: true true false

Code
Scanner scanner = new Scanner("One,5,true,3,true,6,7,false'');
scanner.useDelimiter(",");



【非選題】

179. Place the Relations on their corresponding Implementation Structures. Note Not all Implementation Structures will be used.60c82399836be.jpg



【非選題】

180. Place the correct description of the compiler output on the code fragments to be inserted at lines 4 and 5. The same compiler output may be used more than once. 60c823e35bdfd.jpg60c8240259ef7.jpg



【非選題】

181. Place code into the class so that it compiles and generates the output answer = 42. Note: Code options may be used more than once.60c82432c87ff.jpg60c8244d036c3.jpg



【非選題】

182. Given the class definitions:60c8248d1cbec.jpg60c824ad2ab04.jpg



【非選題】

183. Place the code in the appropriate places such that this program will always output [1, 2]. 60c824da5be72.jpg



【非選題】

184. Place each Collection Type on the statement to which it applies.
60c8250634896.jpg



【非選題】
188. Given a pre-generics implementation of a method:
 11. public static int sum(List list){ 
12. int sum = 0; 
13. for(Iterator iter = list.iterator(); iter.hasNext();){ 
14. int i = ((Integer)iter.next()).intValue();
 15. sum += i; 
16. } 
17. return sum; 
18. } 
What three changes allow the class to be used with generics and avoid an unchecked warning? (Choose three.)
(A) Remove line 14.
(B) Replace line 14 with "int i = iter.next();".
(C) Replace line 13 with "for(int i : intList){".
(D) Replace line 13 with "for(Iterator iter : intList){".
(E) Replace the method declaration with "sum(List<int> intList)". (F) Replace the method declaration with "sum(List<Integer> intList)".


【非選題】
191. Given: 
11. //insert code here
 12. private N min, max;
 13. public N getMin() { return min; } 
14. public N getMax() { return max; } 
15. public void add(N added) { 
16. if(min == null || added.doubleValue() < min.doubleValue()) 
17. min = added; 
18. if(max == null || added.doubleValue() > max.doubleValue()) 
19. max = added; 
20. } 
21. }
 Which two, inserted at line 11, will allow the code to compile? (Choose two.)
(A) public class MinMax<?>{
(B) public class MinMax<? extends Number>{
(C) public class MinMax<N extends Object>{
(D) public class MinMax<N extends Number>{
(E) public class MinMax<? extends Object>{ (F) public class MinMax<N extends Integer>{


【非選題】
199. Given: 
10. interface A{void x();} 
11. class B implements A{public void x(){} public void y(){}}
 12. class C extends B{public void x(){}} 
And: 
20. java.util.List<A> list = new java.util.ArrayList<A>();
 21. list.add(new B()); 
22. list.add(new C()); 
23. for(A a : list){ 
24. a.x();
 25. a.y(); 
26. } 
What is the result?
(A) The code runs with no output.
(B) An exception is thrown at runtime.
(C) Compilation fails because of an error in line 20.
(D) Compilation fails because of an error in line 21.
(E) Compilation fails because of an error in line 23. (F) Compilation fails because of an error in line 25.


試卷測驗 - 104 年 - SCJP 151-200#99330-阿摩線上測驗

邱振盛剛剛做了阿摩測驗,考了2分