1. Given: 2. public class Bunnies { 3. static int count=0; 4. Bunnies() { 5. while (count<10) new Bunnies (++count); 6. } 7. Bunnies (int x) {super();} 8. public static void main (String[] args) { 9. new Bunnies(); 10. new Bunnies (count); 11. System. out. println (count++); 12. } 13. } What is the result?
A.9
B.10
C.11
D.12
E.Compilation fails.
F.An exception is thrown at runtime.
A B C D E F
B
2. Given: 2. public class Jail { 3. private int x=4; 4. public static void main (String[] args) { 5. protected int x=6; 6. new Jail() .new Cell() .slam(); 7. } 8. class Cell { 9. void slam() {System.out.println ("throw away key" + x); } 10. } 11. } Which are true? (Choose all that apply.)
A.Compilation succeeds.
B.The output is "throw away key 4".
C.The output is "throw away key 6".
D.Compilation fails due to an error on line 5.
E.Compilation fails due to an error on line 6.
F.Compilation fails due to an error on line 9.
A B C D E F
D
3. Given: 2. public class Fabric extends Thread { 3. public static void main (String[] args) 4. Thread t=new Thread (new Fabric()); 5. Thread t2=new Thread (new Fabric()); 6. t.start(); 7. t2.start(); 8. } 9. public static void run() { 10. for(int i=0; i<2; i++) 11. System.out.print (Thread.currentThread() .getName() +" "); 12. } 13. } Which are true? (Choose all that apply.)
A.Compilation fails.
B.No output is produced.
C.The output could be Thread-1 Thread-3 Thread-1 Thread-2
D.The output could be Thread-1 Thread-3 Thread-1 Thread-3
E.The output could be Thread-1 Thread-1 Thread-2 Thread-2
F.The output could be Thread-1 Thread-3 Thread-3 Thread-1
G.The output could be Thread-1 Thread-3 Thread-1 Thread-1
A B C D E F G
A
4. Given: 2. class Feline { } 3. public class BarnCat2 extends Feline { 4. public static void main (String[] args) { 5. Feline ff=new Feline(); 6. BarnCat2 b=new BarnCat2 (); 7. // insert code here 8. } 9. } Which, inserted independently at line 7, compile? (Choose all that apply.)
5. Given: 2. public class Choosy { 3. public static void main (String[] args){ 4. String result=" "; 5. int x=7, y=8; 6. if(x==3) {result += "i"; } 7. else if (x>9) {result += "2"; } 8. else if (y<9) {result += "3"; } 9. else if (x==7) {result += "4"; } 10. else {result += "5"; } 11. System.out.println (result); 12. } 13. } What is the result? (Choose all that apply.)
A.3
B.34
C.35
D.345
E.Compilation fails due to an error on line 5.
F.Compilation fails due to errors on lines 8 and 9.
G.Compilation fails due to errors on lines 7, 8, and 9
A B C D E F G
A
6. Given: 1. public class Twine { 2. public static void main (String[] args) { 3. String s=""; 4. StringBuffer sb1=new StringBuffer("hi"); 5. StringBuffer sb2=new StringBuffer("hi"); 6. StringBuffer sb3=new StringBuffer(sb2); 7. StringBuffer sb4=sb3; 8. if(sb1.equals(sb2)) s += "1 "; 9. if(sb2.equals(sb3)) s += "2 "; 10. if(sb3.equals(sb4)) s += "3 "; 11. String s2="hi"; 12. String s3="hi"; 13. String s4=s3; 14. if(s2.equals(s3)) s += "4 "; 15. if(s3.equals(s4)) s += "5 "; 16. System.out.println(s); 17. } 18. } What is the result?
A.13
B.15
C.123
D.145
E.345
F.1345
G.12345
H.Compilation fails.
A B C D E F G H
E
7. Which are true? (Choose all that apply.)
A.All classes of Exception extend Error.
B.All classes of Error extend Exception.
C.All Errors must be handled or declared.
D.All classes of Exception extend Throwable.
E.All Throwables must be handled or declared.
F.All Exceptions must be handled or declared.
G.RuntimeExceptions need never be handled or declared.
A B C D E F G
DG
8. Given: 2. import java.util.*; 3. public class Birthdays { 4. public static void main(String[] args) { 5. Map<Friends, String> hm=new HashMap<Friends, String>(); 6. hm.put(new Friends("Charis"), "Summer 2009"); 7. hm.put(new Friends("Draumur"), "Spring 2002"); 8. Friends f=new Friends(args[0]); 9. System. out.println (hm.get(f)); 10. } 11. } 12. class Friends { 13. String name; 14. Friends(String n) {name=n; } 15. } And the command line invocation: java Birthdays Draumur What is the result? A. null B. Draumur C. Spring 2002 D. Compilation fails. E. The output is unpredictable. F. An exception is thrown at runtime. G Friends@XXXX (where XXXX is a representation of a hashcode)
A B C D E F G
A
9. Given: 2. import java.util.*; 3. class Cereal { } 4. public class Flakes extends Cereal { 5. public static void main(String[] args) { 6. List<Flakes> c0=new List<Flakes>(); 7. List<Cereal> c1=new ArrayList<Cereal>(); 8. List<Cereal> c2=new ArrayList<Flakes>(); 9. List<Flakes> c3=new ArrayList<Cereal>(); 10. List<Object> c4=new ArrayList<Flakes>(); 11. ArrayList<Cereal> c5=new ArrayList<Flakes>(); 12. } 13. } Which are true? (Choose all that apply.)
A.Compilation succeeds.
B.Compilation fails due to an error on line 6.
C.Compilation fails due to an error on line 7.
D.Compilation fails due to an error on line 8.
E.Compilation fails due to an error on line 9.
F.Compilation fails due to an error on line 10.
G.Compilation fails due to an error on line 11.
A B C D E F G
BDEFG
10. Given: 3. public class RediMix extends Concrete { 4. RediMix() {System.out.println("r "); } 5. public static void main(String[] args) { 6. new RediMix(); 7. } 8. } 9. class Concrete extends Sand { 10. Concrete() {System.out.print("c "); 11. private Concrete(String s) { } 12. } 13. abstract class Sand { 14. Sand() {System.out.print("s "); } 15. } What is the result?
A.r
B.c r
C.r c
D.s c r
E.r c s
F.Compilation fails due to a single error in the code.
G.Compilation fails due to multiple errors in the code.
A B C D E F G
D
11. Which statement(s) are true? (Choose all that apply.)
A.Coupling is the OO principle most closely associated with hiding a class's implementation details.
B.Coupling is the OO principle most closely associated with making sure classes know about other classes only through their APIs.
C.Coupling is the OO principle most closely associated with making sure a class is designed with a single, well-focused purpose.
D.Coupling is the OO principle most closely associated with allowing a single object to be seen as having many types.
A B C D
B
12. Given: 2. class Mosey implements Runnable { 3. public void run() { 4. for(int i=0; i<1000; i++) { 5. System.out.print(Thread.currentThread() .getId() +"-"+i+" "); 6. } } } 7. public class Stroll { 8. public static void main(String[] args) throws Exception { 9. Thread t1=new Thread(new Mosey()); 10. //insert code here 11. } 12. } Which of the following code fragments, inserted independently at line 10, will probably run most (or all) of the main thread's run() method invocation before running most of the t1 thread's run() method invocation? (Choose all that apply.)
A.t1.setPriority(1); new Mosey().run(); t1.start();
B.t1.setPriority(9); new Mosey().run(); t1.start();
C.t1.setPriority(1); t1.start(); new Mosey().run();
D.t1.setPriority(8); t1.start(); new Mosey().run();
A B C D
ABC
13. Given: 37. boolean b=false; 38. int i=7; 39. double d=1.23; 40. float f=4.56f; 41. 42. // insert code here Which line(s) of code, inserted independently at line 42, will compile and run without exception? (Choose all that apply.)
15. Given: 3. import java.util.*; 4. public class VLA2 implements Comparator<VLA2> { 5. int dishSize; 6. public static void main(String[] args) { 7. VLA2[] va={new VLA2(40), new VLA2(200), new VLA2(60) }; 8. 9. Arrays.sort(va, va[0]); 10. int index=Arrays.binarySearch(va, new VLA2(40), va[0]); 11. System.out.print(index +" "); 12. index=Arrays.binarySearch(va, new VLA2(80), va[0]); 13. System.out.print(index); 14. } 15. public int compare(VLA2 a, VLA2 b) { 16. return b.dishSize - a.dishSize; 17. } 18. VLA2(int d) {dishSize=d; } 19. } What is the result?
A.0-2
B.0-3
C.2-1
D.2-2
E.Compilation fails.
F.An exception is thrown at runtime.
A B C D E F
D
16. Given a directory structure: - baseDir - testDir - subDir2 - Shackelton.txt and given the following code: 12. String name = "testDir" + File.pathSeparator + "subDir2" + File.pathSeparator + "Shackelton.txt"; 13. File f = new File (name); 14. System.out.println("exists " + f.exists()); Assuming the proper import statements and exception handling, which statements must be true in order for the output to be "exists true"? (Choose three.)
A.Line 12 is correct as it stands.
B.Line 14 is correct as it stands.
C.The program must be invoked from the baseDir directory.
D.The program must be invoked from the testDir directory.
E.Line 12 must use File.separator instead of File.pathSeparator.
F.Line 14 must use the method fileExists() instead of exists().
A B C D E F
BCE
17. Given: 1. import java.io.*; 2. import java.util.*; 3. import static java.lang. Short.*; 4. import static java.lang. Long.*; 5. public class MathBoy { 6. public static void main(String[] args) { 7. long x = 123456789; 8. short y = 22766; // maximum value of a short is 32767 9. System.out.printf("%1$+10d %2$010d ", x, MAX VALUE - y); 10. System.out.println(new Date()); 11. } 12. } Which are true? (Choose all that apply.)
A.Compilation fails.
B.The output will include "+"
C.The output will include "10001"
D.The output will include "0000010001"
E.The output will include today's date.
F.The output will include the number of milliseconds from January 1, 1970 until today.
A B C D E F
A
18. Given: 1. public class WeatherTest { 2. static Weather w; 3. public static void main(String[] args) { 4. System.out.print(w.RAINY.count + " " + w. Sunny . count + " "); 5. } 6. } 7. enum Weather { 8. RAINY, Sunny; 9. int count = 0; 10. Weather() { 11. System.out.print("c "); 12. count++; 13. } 14. } What is the result?
A.c1c1
B.c1c2
C.cc11
D.cc12
E.cc22
F.Compilation fails.
G.An exception is thrown at runtime.
A B C D E F G
C
19. Given: 2. import java.text.*; 3. public class Gazillion { 4. public static void main(String[] args) throws Exception { 5. String s = "123.456xyz"; 6. NumberFormat nf = NumberFormat.getInstance(); 7. System.out.println (nf.parse(s)); 8. nf.setMaximumFractionDigits(2); 9. System.out.println (nf.format(s)); 10. } 11. } Which are true? (Choose all that apply.)
A.Compilation fails.
B.The output will contain "123.45 "
C.The output will contain "123.456"
D.The output will contain "123.456xyz"
E.An exception will be thrown at runtime.
A B C D E
CE
20. Given that the current directory is bigApp, and the following directory structure: bigApp |-- classes |-- com |-- wickedlysmart |-- BigAppMain.class And the code: package com.wickedlysmart; public class BigAppMain { public static void main(String[] args) { System. out.println("big app"); } } Which will invoke BigAppMain? (Choose all that apply.)
21. Given: 2. class Game { 3. static String s = "-"; 4. String s2 = "s2"; 5. Game (String arg) {s += arg; } 6. } 7. public class Go extends Game { 8. Go() {super(s2); } 9. {s += "i "; } 10. public static void main(String[] args) { 11. new Go (); 12. System.out.println(s); 13. } 14. static {s += "sb "; } 15. } What is the result?
A.-sb i s2
B.-sb s2 i
C.-s2 i sb
D.-s2 sb i
E.Compilation fails.
F.An exception is thrown at runtime.
A B C D E F
E
22. Given: 2. public class Salmon extends Thread { 3. public static long id; 4. public void run() { 5. for(int i = 0; i<4; i++) { 6. // insert code here 7. new Thread(new Salmon()) .start(); 8. throw new Error(); 9. } 10. System.out.print (i +" "); 11. } } 12. public static void main(String[] args) { 13. Thread t1 = new Salmon(); 14. id = t1.getId(); 15. t1.start (); 16. } } And the two code fragments: Ⅰ. if(i == 2 && id == Thread.currentThread().getId()) { Ⅱ. if(i == 2) { When inserting either fragment, independently at line 6, which are true? (Choose all that apply.)
A.Both fragments produce the same output.
B.Both fragments will end in about the same amount of time.
C.Compilation fails, regardless of which fragment is inserted.
D.Regardless of which fragment is inserted, output ends once the Error is thrown.
E.Regardless of which fragment is inserted, output continues after the Error is thrown.
A B C D E
E
23. Given: 2. public class Internet { 3. private int y = 8; 4. public static void main(String[] args) { 5. new Internet() .go(); 6. } 7. void go() { 8. int x = 7; 9. TCPIP ip = new TCPIP(); 10. class TCPIP { 11. void doit() {System.out.println(y + x); 12. } 13. ip.doit (); 14. } 15. } What is the result? (Choose all that apply.)
A.Compilation succeeds.
B.Compilation fails due to an error on line 3.
C.Compilation fails due to an error on line 8.
D.Compilation fails due to an error on line 9.
E.Compilation fails due to an error on line 10.
F.Compilation fails due to accessing x on line 11.
G.Compilation fails due to accessing y on line 11.
A B C D E F G
DF
24. Given: 4. public static void main(String[] args) { 5. try { 6. if(args.length == 0) throw new Exception(); 7. } 8. catch (Exception e) { 9. System.out .print ("done "); 10. doStuff(); // assume this method compiles 11. } 12. finally { 13. System.out.println("finally "); 14. } 15. } Which are possible outputs? (Choose all that apply.)
A."done "
B."finally"
C."done finally"
D.Compilation fails.
E.No output is produced.
A B C D E
ABC
25. Given: 3. class A { } 4. class B extends A { } 5. class C extends B { } 6. public class Carpet<V extends B> { 7. public <X extends V> Carpet<? extends V> method(Carpet<? super X> e) { 8. // insert code here 9. } } Which, inserted independently at line 8, will compile? (Choose all that apply.)
A.return new Carpet<X>();
B.return new Carpet<V>();
C.return new Carpet<A>();
D.return new Carpet<B>();
E.return new Carpet<C>();
A B C D E
AB
26. Given: 1. class One { 2. int x = 0; 3. {assert x == i; } 4. } 5. public class Two { 6. public static void main(String[] args) { 7. int y = 0; 8. assert y == 0; 9. if(args.length > 0) 10. new One(); 11. } 12. } Which of the following will mn without error? (Choose all that apply.)
A.java Two
B.java Two x
C.java -ea Two
D.java -ea Two x
E.java -ea:One Two
F.java -ea:One Two x
G.java -ea:Two Two x
A B C D E F G
ABCEG
27. Given: 2. class SafeDeposit { 3. private static SafeDeposit singleton; 4. public static SafeDeposit getInstance(int code) { 5. if(singleton == null) 6. singleton = new SafeDeposit(code); 7. return singleton; 8. } 9. private int code; 10. private SafeDeposit(int c) { code = c; } 11. int getCode() {return code; } 12. } 13. public class BeSafe { 14. // insert lots of code here 25. } Which are true? (Choose all that apply.)
A.Compilation fails.
B.Class BeSafe can create many instances of SafeDeposit.
C.Class BeSafe CANNOT create any instances of SafeDeposit.
D.Class BeSafe can create only one instance of SafeDeposit.
E.Class BeSafe can create instances of SafeDeposit without using the getInstance() method.
F.Once class BeSafe has created an instance of SafeDeposit, it cannot change the value of the instance's "code" variable.
A B C D E F
BF
28. Given: 2. public class DMV implements Runnable { 3. public static void main(String[] args) { 4. DMV d = new DMV(); 5. new Thread(d) .start(); 6. Thread t1 = new Thread(d); 7. tl.start(); 8. } 9. public void run() { 10. for(int j = 0; j < 4; j++) {do1(); do2(); } 11. } 12. void do1() { 13. try {Thread.sleep(1000); } 14. catch (Exception e) {System.out.print("e "); } 15. } 16. synchronized void do2() { 17. try {Thread.sleep(1000); } 18. catch (Exception e) {System.out.print("e "); 19. } } Which are tree? (Choose all that apply.)
A.Compilation fails.
B.The program's minimum execution time is about 8 seconds.
C.The program's minimum execution time is about 9 seconds.
D.The program's minimum execution time is about 12 seconds.
E.The program's minimum execution time is about 16 seconds.
F.Un-synchronizing do2() changes the program's minimum execution time by only a few milliseconds.
A B C D E F
C
29. Given: 2. public class Bang extends Thread { 3. static Thread t1, t2, t3; 4. public static void main(String[] args) throws Exception { 5. t1 = new Thread(new Bang()); 6. t2 = new Thread(new Bang()); 7. t3 = new Thread(new Bang()); 8. t1.start(); t2.start(); t3.start(); 9. } 10. public void run() { 11. for(int i = 0; i < 500; i++) { 12. System.out.print(Thread.currentThread() .getId() + " "); 13. if(i == 250) 14. try { 15. System.out.print ("**" + tl.getId() + "**"); 16. t1.sleep(600); 17. } 18. catch (Exception e) { } 19. } } } Which are true? (Choose all that apply.)
A.Compilation fails.
B.An exception is thrown at runtime.
C.Bang will execute for a second or two.
D.Bang will execute for at least 10 minutes.
E.Thread t1 will almost certainly be the last thread to finish.
F.Thread t1 will almost certainly be the first thread to finish.
G.It's difficult to predict which thread will be the last to finish.
A B C D E F G
CG
30. Given: 3. public class Dec26 { 4. public static void main(String[] args) 5. short a1 = 6; 6. new Dec26() .go(a1); 7. new Dec26() .go(new Integer(7)); 8. } 9. void go(Short x) {System.out.print("S "); } 10. void go(Long x) {System.out.print("L "); } 11. void go(int x) {System.out.print("i "); } 12. void go(Number n) {System.out.print("N "); 13. } What is the result?
A.iL
B.iN
C.SL
D.SN
E.Compilation fails.
F.An exception is thrown at runtime.
A B C D E F
B
31. Given: 1. public class Fellowship { 2. public static void main(String[] args) { 3. // insert code here 4. } 5. } 6. class Numinor { 7. enum Members { 8. HOBBITS(48), ELVES(74), DWARVES(50); 9. int height; 10. Members(int h) {height = h; } 11. int getHeight() {return height; } 12. } 13. } And these four lines of code to be inserted, independently at line 3: Ⅰ. int h0 = Numinor.Members.HOBBITS.getHeight(); Ⅱ. int h1 = Numinor.Members.getHeight(); Ⅲ. int h2 = Members.HOBBITS.getHeight(); Ⅳ. int h3 = Members.height; Which are true? (Choose all that apply.)
A.Line Ⅰ will compile.
B.Line Ⅱ will compile.
C.Line Ⅲ will compile.
D.Line Ⅳ will compile.
E.Class Numinor will NOT compile.
A B C D E
A
32. Given: 2. public class Volume { 3. Volume v; 4. int size; 5. public static void main(String[] args) 6. Volume myV = new Volume(); 7. final Volume v2; 8. v2 = myV.doStuff(myV); 9. v2.v.size = 7; 10. System.out.print (v2. size); 11. } 12. Volume doStuff(Volume v3) { 13. v3.size = 5; 14. v3.v = new Volume(); 15. return v3; 16. } } What is the result? (Choose all that apply.)
A.5
B.7
C.Compilation fails due to an error on line 8.
D.Compilation fails due to an error on line 9.
E.Compilation fails due to an error on line 13.
F.Compilation fails due to an error on line 14.
A B C D E F
A
33. Given: 3. public class BirdHouse { 4. public static void main(String[] args) 5. String r = "0"; 6. int x = -1, y = -5; 7. if(x < 5) 8. if(y > 0) 9. if(x > y) 10. r += "1"; 11. else r += "2"; 12. else r += "3"; 13. else r += "4"; 14. System.out.println(r); 15. } } What is the result?
A.0
B.01
C.02
D.03
E.013
F.023
G.Compilation fails.
A B C D E F G
D
34. Given: 1. class c1 { } 2. class c2 { } 3. interface i1 { } 4. interface i2 { } 5. class A extends c2 implements i1 { } 6. class B implements i1 implements i2 { } 7. class C implements c1 { } 8. class D extends cl, implements i2 { } 9. class E extends i1, i2 { } 10. class F implements i1, i2 { } What is the result? (Choose all that apply.) A. Class A does not compile. B. Class B does not compile. C. Class C does not compile. D. Class D does not compile. E. Class E does not compile. E. Class F does not compile. G. Compilation succeeds for all of the classes.
A B C D E F G
BCDE
35. Given that "it, IT" and "pt" are valid Locale codes, and given: 41. Date d = new Date(); 42. DateFormat df; 43. Locale[] la = {new Locale ("it", "IT"), new Locale("pt") }; 44. for(Locale i: la) { 45. df = DateFormat.getDateInstance(DateFormat. FULL, i); 46. System.out.println(d.format (df)); 47. } Which are true? (Choose all that apply.)
A.An exception will be thrown at runtime.
B.Compilation fails due to an error on line 43.
C.Compilation fails due to an error on line 45.
D.Compilation fails due to an error on line 46.
E.Classes from the java.text package are used in this code.
F.Classes from the java.util package are used in this code.
A B C D E F
DEF
36. Given: 2. class SuperCool { 3. static String os = ""; 4. void doStuff() {os += "super "; } 5. } 6. public class Cool extends SuperCool { 7. public static void main(String[] args) { 8. new Cool() .go(); 9. } 10. void go() { 11. SuperCool s = new Cool(); 12. Cool c = (Cool)s; 13. // insert code here 14. } 15. void doStuff() { os += "cool "; } 16. } If the rest of the code compiles, which line(s) of code, inserted independently at line 13, compile? (Choose all that apply.)
A.c.doStuff();
B.s.doStuff();
C.this.doStuff();
D.super.doStuff();
E.c.super.doStuff();
F.s.super.doStuff();
G.this.super.doStuff();
H.There are other errors in the code.
A B C D E F G H
ABCD
37. Given: 5. static String s = ""; 6. public static void main(String[] args) { 7. try {doStuff(args); } 8. catch (Error e) {s += "e "; } 9. s += "x "; 10. System.out.println (s); 11. } 12. static void doStuff(String[] args) { 13. if(args.length == 0) 14. throw new IllegalArgumentException(); 15. s += "d "; 16. } And, if the code compiles, and given a java invocation with no arguments, what is the result? (Choose all that apply.)
A.dx
B.ex
C.dex
D.Compilation fails due to an error on line 8.
E.Compilation fails due to an error on line 12.
F.Compilation fails due to an error on line 14.
G.An uncaught IllegalArgumentException is thrown.
A B C D E F G
G
38. Given: 2. class Paratrooper implements Runnable { 3. public void run() { 4. System.out.print (Thread. currentThread() .getName() +" "); 5. } } 6. public class Jump { 7. static Paratrooper p; 8. static {p = new Paratrooper(); } 9. {Thread t1 = new Thread(p, "bob"); t1.start(); } 10. public static void main(String[] args) { 11. new Jump(); 12. new Thread(new Runnable() {public void run() {; } }, "carol").start(); 13. new Thread(new Paratrooper(), "alice").start(); 14. } 15. Jump() {Thread t2 = new Thread(p, "ted"); t2.start();} 16. } Which are true? (Choose all that apply.)
A.The output could be ted bob alice
B.The output could be bob alice carol
C.The output could be bob carol ted alice
D.Compilation fails due to an error on line 8.
E.Compilation fails due to an error on line 9.
F.Compilation fails due to an error on line 12.
G.Compilation fails due to an error on line 15.
A B C D E F G
A
39. Which are true? (Choose all that apply.)
A.For a specific object, it's NOT possible for finalize() to be invoked more than once.
B.It's possible for objects, on whom finalize() has been invoked by the JVM, to avoid the GC.
C.Overriding finalize() ensures that objects of that type will always be GCed when they become eligible.
D.The finalize() method is invoked only for GC-eligible objects that are NOT part of "islands of isolation."
E.For every object that the GC considers collecting, the GC remembers whether finalize() has been invoked for that specific object.
A B C D E
BE
40. Given that: Exception is the superclass of IOException and IOException is the superclass of FileNotFoundException and 2. import java.io.*; 3. class Author { 4. protected void write() throws IOException { } 5. } 6. public class Salinger extends Author { 7. private void write(int x) { } 8. protected void write (long x) throws FileNotFoundException { } 9. protected void write (boolean x) throws Exception { } 10. protected int write(short x) {return 7; } 11. public void write() { } 12. } What is the result? (Choose all that apply.)
A.Compilation succeeds.
B.Compilation fails due to an error on line 7.
C.Compilation fails due to an error on line 8.
D.Compilation fails due to an error on line 9.
E.Compilation fails due to an error on line 10.
F.Compilation fails due to an error on line 11.
A B C D E F
A
41. Given: 2. class Chilis { 3. Chilis (String c, int h) {color = c; hotness = h; } 4. String color; 5. int hotness; 6. public boolean equals(Object o) { 7. if(this == (Chilis)o) return true; 8. return false; 9. } 10. public String toString() {return color + " " + hotness; } 11. } If instances of class Chilis are to be used as keys in a Map, which are true? (Choose all that apply.)
A.Without overriding hashCode(), the code will not compile.
B.As it stands, the equals() method has been legally overridden.
C.It's possible for such keys to find the correct entries in the Map.
D.It's NOT possible for such keys to find the correct entries in the Map.
E.As it stands, the Chilis class legally supports the equals() and hashCode() contracts.
F.IfhashCode() was correctly overridden, it would make retrieving Map entries by key easier.
A B C D E F
BCE
42. Given: 2. public class Contact { 3. private String name; 4. private String city; 5. String getName() {return name; } 6. void setName(String n) {name = n; } 7. void setCity(String c) { 8. if(c == null) throw new NullPointerException(); 9. city = c; 10. } 11. String getCity() {return city; } 12. } Which are true? (Choose all that apply.)
A.Compilation fails.
B.The class is well encapsulated.
C.The setCity() method is an example of loose coupling.
D.The setCity() method has better encapsulation than setName().
E.The setCity() method is cohesive; the setName() method is not.
A B C D E
B
43. Given the current directory is bigApp, and the directory structure: bigApp |-- classes |-- Cloned. class And the file: public class Cloned { public static void main(String[] args) { System.out.println ("classes"); assert(Integer.parseInt(args[0]) > 0); } } Which will produce the output "classes" followed by an AssertionError? (Choose all that apply.)
A.java -cp classes Cloned -4
B.java -cp classes -ca Cloned
C.java -ea-cp classes Cloned -4
D.java -ca -cp classes Cloned 4
E.java -ea, cp classes Cloned 4
F.java -ea -cp classes Cloned -4
G.java -cp classes Cloned -4 -ea
A B C D E F G
F
44. Given: 1. interface Syrupable { 2. void getSugary(); 3. } 4. abstract class Pancake implements Syrupable { } 5. 6. class BlueBerryPancake implements Pancake { 7. public void getSugary() { ; } 8. } 9. class SourdoughBlueBerryPancake extends BlueBerryPancake { 10. void getSugary(int s) { ; } 11. } Which are true? (Choose all that apply.)