Tuesday 4 October 2011

scjp set2

Question set2

QUESTION NO: 301
Given:
11. public class Commander {
12. public static void main(String[] args) {
13. String myProp = /* insert code here */
14. System.out.println(myProp);
15. }
16. }
and the command line:
java -Dprop.custom=gobstopper Commander
Which two, placed on line 13, will produce the output gobstopper? (Choose two.)
A. System.getProperties().getProperty("prop.custom");//  this is ans
B. System.getenv("prop.custom");
C. System.load("prop.custom");
D. System.property("prop.custom");
E. System.getProperty("prop.custom");         // this is ans

QUESTION NO: 302
Given:
11. rbo = new ReallyBigObject();
12. // more code here
13. rbo = null;
14. /* insert code here */
Which statement should be placed at line 14 to suggest that the virtual machine expend effort
toward recycling the memory used by the object rbo?
A. System.freeMemory();
B. Runtime.getRuntime().freeMemory();
C. Runtime.getRuntime().growHeap();
D. System.gc();
E. Runtime.gc();// ans
QUESTION NO: 303
Which three statements are true? (Choose three.)
A. A protected method in class X can be overridden by any subclass of X.
B. A final method in class X can be abstract if and only if X is abstract.
C. A private static method can be called only within other static methods in class X.
D. A non-static public final method in class X can be overridden in any subclass of X.
E. A method with the same signature as a private final method in class X can be implemented in a
subclass of X.
F. A protected method in class X can be overridden by a subclass of A only if the subclass is in the
same package as X.
G. A public static method in class X can be called by a subclass of X without explicitly referencing
the class X.
QUESTION NO: 304
Click the Exhibit button.
Which three code fragments, added individually at line 29, produce the output 100? (Choose
three.)
A. n = 100;
B. o.setY( i ); i = new Inner(); i.setX( 100 );
C. i.setX( 100 );
D. i = new Inner(); i.setX( 100 ); o.setY( i );
E. o.getY().setX( 100 );
F. i = new Inner(); i.setX( 100 );
QUESTION NO: 305
Click the Exhibit button.
What is the outcome of the code?
A. Gobstopper
Fizzylifting
B. Scrumdiddlyumptious
Fizzylifting
C. Compilation fails.
D. Gobstopper
Scrumdiddlyumptious   
E. Scrumdiddlyumptious
QUESTION NO: 306
Click the Exhibit button.
Which statement is true about the classes and interfaces in the exhibit?
A. Compilation will succeed for all classes and interfaces.
B. Compilation of class C will fail because of an error in line 2.
C. Compilation of class AImpl will fail because of an error in line 2.
D. Compilation of class C will fail because of an error in line 6.
QUESTION NO: 307
When comparing java.io.BufferedWriter to java.io.FileWriter, which capability exists as a method in
only one of the two?
A. closing the stream
B. writing to the stream
C. marking a location in the stream
D. flushing the stream
E. writing a line separator to the stream
 QUESTION NO: 308 DRAG DROP

Click the Task button.

QUESTION NO: 309
Given:
13. public static void search(List<String> list) {
14. list.clear();
15. list.add("b");
16. list.add("a");
17. list.add("c");
18. System.out.println(Collections.binarySearch(list, "a"));
19. }
What is the result of calling search with a valid List implementation?
A. 0
B. 1
C. a
D. c
E. 2
F. The result is undefined.
G. b
QUESTION NO: 310
Given:
1. public class Threads3 implements Runnable {
2. public void run() {
3. System.out.print("running");
4. }
5. public static void main(String[] args) {
6. Thread t = new Thread(new Threads3());
7. t.run();
8. t.run();
9. t.start();
10. }
11. }
What is the result?
A. Compilation fails.
B. An exception is thrown at runtime.
C. The code executes and prints "runningrunningrunning".// ans
D. The code executes and prints "running".
E. The code executes and prints "runningrunning".
QUESTION NO: 311 DRAG DROP
Click the Task button.


QUESTION NO: 312
Click the Exhibit button.

Which statement is true about the two classes?
A. Compilation of class B will fail. Compilation of class A will succeed.
B. Compilation of both classes will fail.
C. Compilation of both classes will succeed.
D. Compilation of class A will fail. Compilation of class B will succeed.
QUESTION NO: 313 DRAG DROP
Click the Task button.


QUESTION NO: 314
Given:
d is a valid, non-null Date object
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.setDateFormat(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.format(d));
D. Locale loc = Locale.getDefault();
System.out.println(loc.getDisplayCountry()
+ " " + df.setDateFormat(d));
QUESTION NO: 315
Given:
11. public class Ball{
12. public enum Color { RED, GREEN, BLUE };
13. public void foo(){
14. // insert code here
15. { System.out.println(c); }
16. }
17. }
Which code inserted at line 14 causes the foo method to print RED, GREEN, and BLUE?
A. for( Color c = Color[0]; c <= Color[2]; c++ )
B. for( Color c ; c.hasNext() ; c.next() )
C. for( Color c = Color.RED; c <= Color.BLUE; c++ )
D. for( Color c = RED; c <= BLUE; c++ )
E. for( Color c : Color.values() )
QUESTION NO: 316
Given:
11. public class Key {
12. private long id1;
13. private long id2;
14.
15. // class Key methods
16. }
A programmer is developing a class Key, that will be used as a key in a standard
java.util.HashMap.
Which two methods should be overridden to assure that Key works correctly as a key? (Choose
two.)
A. public int compareTo(Object o)
B. public boolean equals(Object o)
C. public int hashCode()
D. public boolean equals(Key k)
E. public boolean compareTo(Key k)
QUESTION NO: 317
Given:
13. public class Pass {
14. public static void main(String [] args) {
15. int x = 5;
16. Pass p = new Pass();
17. p.doStuff(x);
18. System.out.print(" main x = " + x);
19. }
20.
21. void doStuff(int x) {
22. System.out.print(" doStuff x = " + x++);
23. }
24. }
What is the result?
A. doStuff x = 6 main x = 5
B. doStuff x = 5 main x = 5
C. doStuff x = 6 main x = 6
D. Compilation fails.
E. An exception is thrown at runtime.
F. doStuff x = 5 main x = 6
QUESTION NO: 318
Given:
1. public class TestOne {
2. public static void main (String[] args) throws Exception {
3. Thread.sleep(3000);
4. System.out.println("sleep");
5. }
6. }
What is the result?
A. The code executes normally and prints "sleep".          // ans....
B. An exception is thrown at runtime.
C. The code executes normally, but nothing is printed.
D. Compilation fails.
QUESTION NO: 319 DRAG DROP
Click the Task button.

QUESTION NO: 320
Given:
11. Float pi = new Float(3.14f);
12. if (pi > 3) {
13. System.out.print("pi is bigger than 3. ");
14. }
15. else {
16. System.out.print("pi is not bigger than 3. ");
17. }
18. finally {
19. System.out.println("Have a nice day.");
20. }
What is the result?
A. Compilation fails.                // finelly with out try...
B. An exception occurs at runtime.
C. pi is not bigger than 3. Have a nice day.
D. pi is bigger than 3. Have a nice day.
E. pi is bigger than 3.
QUESTION NO: 321
Given:
1. import java.util.*;
2. public class Example {
3. public static void main(String[] args) {
4. // insert code here
5. set.add(new Integer(2));
6. set.add(new Integer(1));
7. System.out.println(set);
8. }
9. }
Which code, inserted at line 4, guarantees that this program will output [1, 2]?
A. Set set = new LinkedHashSet();
B. Set set = new HashSet();
C. List set = new SortedList();
D. Set set = new SortedSet();
E. Set set = new TreeSet();
QUESTION NO: 322
Given:
foo and bar are public references available to many other threads. foo refers to a Thread and bar
is an Object. The thread foo is currently executing bar.wait().
From another thread, what provides the most reliable way to ensure that foo will stop executing
wait()?
A. Object.notify();
B. bar.notifyAll();
C. Thread.notify();
D. foo.notify();
E. foo.notifyAll();
F. bar.notify();
QUESTION NO: 323
Given:
11. public class ItemTest {
12. private final int id;
13. public ItemTest(int id) { this.id = id; }
14. public void updateId(int newId) { id = newId; }
15.
16. public static void main(String[] args) {
17. ItemTest fa = new ItemTest(42);
18. fa.updateId(69);
19. System.out.println(fa.id);
20. }
21. }
What is the result?
A. The attribute id in the Item object is modified to the new value.
B. Compilation fails.// finel value  will    not be  changed
C. An exception is thrown at runtime.
D. A new Item object is created with the preferred value in the id attribute.
E. The attribute id in the Item object remains unchanged.
QUESTION NO: 324 DRAG DROP
Click the Task button.

QUESTION NO: 325
Given:
1. public class Base {
2. public static final String FOO = "foo";
3. public static void main(String[] args) {
4. Base b = new Base();
5. Sub s = new Sub();
6. System.out.print(Base.FOO);
7. System.out.print(Sub.FOO);
8. System.out.print(b.FOO);
9. System.out.print(s.FOO);
10. System.out.print(((Base)s).FOO);
11. } }
12. class Sub extends Base {public static final String FOO="bar";}
What is the result?
A. foobarfoofoofoo
B. foofoofoobarbar
C. foobarfoobarfoo
D. foobarfoobarbar
E. foofoofoofoofoo
F. foofoofoobarfoo#G. barbarbarbarbar
ans=c.

No comments:

Post a Comment