Java Dump 290
Given the following six method names: addListener addMouseListener setMouseListener deleteMouseListener removeMouseListener registerMouseListener How many of these method names follow JavaBean Listener naming rules? A. 1 B. 2 C. 3 D. 4 E. 5
B. 2
Given: Runnable r = new Runnable() { public void run() { System.out.print("Cat"); } }; Thread t = new Thread(r) { public void run() { System.out.print("Dog"); } }; t.start(); What is the result? A. Cat B. Dog C. Compilation fails. D. The code runs with no output. E. An exception is thrown at runtime
B. Dog
Given: public class Yippee { public static void main(String [] args) { for(int x = 1; x < args.length; x++) { System.out.print(args[x] + " "); } } } and two separate command line invocations: java Yippee java Yippee 1 2 3 4 What is the result? A. No output is produced. 1 2 3 B. No output is produced. 2 3 4 C. No output is produced. 1 2 3 4 D. An exception is thrown at runtime. 1 2 3 E. An exception is thrown at runtime. 2 3 4 F. An exception is thrown at runtime. 1 2 3 4
B. No output is produced. 2 3 4
Given: public class Threads5 { public static void main (String[] args) { new Thread(new Runnable() { public void run() { System.out.print("bar"); }}).start(); } } What is the result? A. Compilation fails. B. An exception is thrown at runtime. C. The code executes normally and prints "bar". D. The code executes normally, but nothing prints.
C. The code executes normally and prints "bar".
public class TestString1 { public static void main(String[] args) { String str = "420"; str += 42; System.out.print(str); } } What is the output? A. 42 B. 420 C. 462 D. 42042 E. Compilation fails. F. An exception is thrown at runtime
D. 42042
class Nav{ public enum Direction { NORTH, SOUTH, EAST, WEST } } public class Sprite{ // insert code here } Which code, inserted at line 14, allows the Sprite class to compile? A. Direction d = NORTH; B. Nav.Direction d = NORTH; C. Direction d = Direction.NORTH; D. Nav.Direction d = Nav.Direction.NORTH;
D. Nav.Direction d = Nav.Direction.NORTH;
Given that the current directory is empty, and that the user has read and write permissions, and the following: import java.io.*; public class DOS { public static void main(String[] args) { File dir = new File("dir"); dir.mkdir(); File f1 = new File(dir, "f1.txt"); try { f1.createNewFile(); } catch (IOException e) { ; } File newDir = new File("newDir"); dir.renameTo(newDir); } } Which statement is true? A. Compilation fails. B. The file system has a new empty directory named dir. C. The file system has a new empty directory named newDir. D. The file system has a directory named dir, containing a file f1.txt. E. The file system has a directory named newDir, containing a file f1.txt.
E. The file system has a directory named newDir, containing a file f1.txt.
Given: 01. public class LineUp { 02. public static void main(String[] args) { 03. double d = 12.345; 04. // insert code here 05. } 06. } Which code fragment, inserted at line 4, produces the output | 12.345|? A. System.out.printf("|%7d| \n", d); B. System.out.printf("|%7f| \n", d); C. System.out.printf("|%3.7d| \n", d); D. System.out.printf("|%3.7f| \n", d); E. System.out.printf("|%7.3d| \n", d); F. System.out.printf("|%7.3f| \n", d);
F. System.out.printf("|%7.3f| \n", d);
Given: class ClassA { public int numberOfInstances; protected ClassA(int numberOfInstances) { this.numberOfInstances = numberOfInstances; } } public class ExtendedA extends ClassA { private ExtendedA(int numberOfInstances) { super(numberOfInstances); } public static void main(String[] args) { ExtendedA ext = new ExtendedA(420); System.out.print(ext.numberOfInstances); } } Which statement is true? A. 420 is the output. B. An exception is thrown at runtime. C. All constructors must be declared public. D. Constructors CANNOT use the private modifier. E. Constructors CANNOT use the protected modifier.
A. 420 is the output.
Given: Float pi = new Float(3.14f); if (pi > 3) { System.out.print("pi is bigger than 3. "); } else { System.out.print("pi is not bigger than 3. "); } finally { System.out.println("Have a nice day."); } What is the result? A. Compilation fails. B. pi is bigger than 3. C. An exception occurs at runtime. D. pi is bigger than 3. Have a nice day. E. pi is not bigger than 3. Have a nice day.
A. Compilation fails.
Given: public class A{ private int counter = 0; public static int getInstanceCount() { return counter; } public A() { counter++; } } Given this code from Class B: 25. A a1 = new A(); 26. A a2 = new A(); 27. A a3 = new A(); 28. System.out.println(A.getInstanceCount()); What is the result? A. Compilation of class A fails. B. Line 28 prints the value 3 to System.out. C. Line 28 prints the value 1 to System.out. D. A runtime error occurs when line 25 executes. E. Compilation fails because of an error on line 28.
A. Compilation of class A fails.
Which two statements are true? (Choose two.) A. It is possible for more than two threads to deadlock at once. B. The JVM implementation guarantees that multiple threads cannot enter into a deadlocked state. C. Deadlocked threads release once their sleep() method's sleep duration has expired. D. Deadlocking can occur only when the wait(), notify(), and notifyAll() methods are used incorrectly. E. It is possible for a single-threaded application to deadlock if synchronized blocks are used incorrectly. F. If a piece of code is capable of deadlocking, you cannot eliminate the possibility of deadlocking by inserting invocations of Thread.yield().
A. It is possible for more than two threads to deadlock at once. F. If a piece of code is capable of deadlocking, you cannot eliminate the possibility of deadlocking by inserting invocations of Thread.yield().
Which two statements are true? (Choose two.) A. It is possible to synchronize static methods. B. When a thread has yielded as a result of yield(), it releases its locks. C. When a thread is sleeping as a result of sleep(), it releases its locks. D. The Object.wait() method can be invoked only from a synchronized context. E. The Thread.sleep() method can be invoked only from a synchronized context. F. When the thread scheduler receives a notify() request, and notifies a thread, that thread immediately releases its lock.
A. It is possible to synchronize static methods D. The Object.wait() method can be invoked only from a synchronized context.
Given: 35. String #name = "Jane Doe"; 36. int $age = 24; 37. Double _height = 123.5; 38. double ~temp = 37.5; Which two statements are true? (Choose two.) A. Line 35 will not compile. B. Line 36 will not compile. C. Line 37 will not compile. D. Line 38 will not compile.
A. Line 35 will not compile. D. Line 38 will not compile.
A team of programmers is reviewing a proposed API for a new utility class. After some discussion, they realize that they can reduce the number of methods in the API without losing any functionality. If they implement the new design, which two OO principles will they be promoting? A. Looser coupling B. Tighter coupling C. Lower cohesion D. Higher cohesion E. Weaker encapsulation F. Stronger encapsulation
A. Looser coupling
Given: 11. public enum Title { 12. MR("Mr."), MRS("Mrs."), MS("Ms."); 13. private final String title; 14. private Title(String t) { title = t; } 15. public String format(String last, String first) { 16. return title + " " + first + " " + last; 17. } 18. } 19. 20. public static void main(String[] args) { 21. System.out.println(Title.MR.format("Doe", "John")); 22. } What is the result? A. Mr. John Doe B. An exception is thrown at runtime. C. Compilation fails because of an error in line 12. D. Compilation fails because of an error in line 15. E. Compilation fails because of an error in line 21.
A. Mr. John Doe
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)
A. Remove line 14. C. Replace line 13 with for (int i : intList) { F. Replace the method declaration with sum(List<Integer> intList)
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 "); F. char[] c = c.readLine("%s", "name ");
A. String s = c.readLine(); E. String s = c.readLine("%s", "name ");
Given: 01. public class Person { 02. private String name; 03. public Person(String name) { this.name = name; } 04. public boolean equals(Person p) { 05. return p.name.equals(this.name); 06. } 07. } 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.
A. The equals method does NOT properly override the Object.equals method.
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 java.util.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.
A. The expressions (ONE == ONE) and ONE.equals(ONE) are both guaranteed to be true.
Given: class Thingy { Meter m = new Meter(); } class Component { void go() { System.out.print("c"); } } class Meter extends Component { void go() { System.out.print("m"); } } class DeluxeThingy extends Thingy { public static void main(String[] args) { DeluxeThingy dt = new DeluxeThingy(); dt.m.go(); Thingy t = new DeluxeThingy(); t.m.go(); } } Which two are true? (Choose two.) A. The output is mm. B. The output is mc. C. Component is-a Meter. D. Component has-a Meter. E. DeluxeThingy is-a Component. F. DeluxeThingy has-a Component.
A. The output is mm. F. DeluxeThingy has-a Component.
QUESTION 34 Given: class Foo { public int a = 3; public void addFive() { a += 5; System.out.print("f "); } } class Bar extends Foo { public int a = 8; public void addFive() { this.a += 5; System.out.print("b " ); } } Invoked with: Foo f = new Bar(); f.addFive(); System.out.println(f.a); What is the result? A. b 3 B. b 8 C. b 13 D. f 3 E. f 8 F. f 13 G. Compilation fails.
A. b 3
Given 11. public interface Status { 12. /* insert code here */ int MY_VALUE = 10; 13. } Which three are valid on line 12? (Choose three.) A. final B. static C. native D. public E. private F. abstract G. protected
A. final B. static D. public
Given: package com.sun.scjp; public class Geodetics { public static final double DIAMETER = 12756.32; // kilometers } Which two correctly access the DIAMETER member of the Geodetics class? (Choose two.) A. import com.sun.scjp.Geodetics; public class TerraCarta { public double halfway() { return Geodetics.DIAMETER/2.0; } } B. import static com.sun.scjp.Geodetics; public class TerraCarta{ public double halfway() { return DIAMETER/2.0; } } C. import static com.sun.scjp.Geodetics.*; public class TerraCarta { public double halfway() { return DIAMETER/2.0; } } D. package com.sun.scjp; public class TerraCarta { public double halfway() { return DIAMETER/2.0; } }
A. import com.sun.scjp.Geodetics; public class TerraCarta { public double halfway() { return Geodetics.DIAMETER/2.0; } } C. import static com.sun.scjp.Geodetics.*; public class TerraCarta { public double halfway() { return DIAMETER/2.0; } }
1. public class TestFive { 2. private int x; 3. 4. public void foo() { 5. int current = x; 6. x = current + 1; 7. } 8. 9. public void go() { 10. for(int i = 0; i < 5; i++) { 11. new Thread() { 12. public void run() { 13. foo(); 14. System.out.print(x + ", "); 15. } 16. }.start(); 17. } 18. } 19.} Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ? (Choose two.) A. move the line 14 print statement into the foo() method B. change line 9 to public synchronized void go() { C. change the variable declaration on line 2 to private volatile int x; D. wrap the code inside the foo() method with a synchronized( this ) block E. wrap the for loop code inside the go() method with a synchronized block synchronized(this) { // for loop code here }
A. move the line 14 print statement into the foo() method D. wrap the code inside the foo() method with a synchronized( this ) block
Given: class ClassA {} class ClassB extends ClassA {} class ClassC extends ClassA {} and: ClassA p0 = new ClassA(); ClassB p1 = new ClassB(); ClassC p2 = new ClassC(); ClassA p3 = new ClassB(); ClassA p4 = new ClassC(); Which three are valid? (Choose three.) A. p0 = p1; B. p1 = p2; C. p2 = p4; D. p2 = (ClassC)p1; E. p1 = (ClassB)p3; F. p2 = (ClassC)p4;
A. p0 = p1; E. p1 = (ClassB)p3; F. p2 = (ClassC)p4;
01. public class Blip { 02. protected int blipvert(int x) { return 0; } 03. } 04. class Vert extends Blip { 05. // insert code here 06. } Which five methods, inserted independently at line 5, will compile? (Choose five.) A. public int blipvert(int x) { return 0; } B. private int blipvert(int x) { return 0; } C. private int blipvert(long x) { return 0; } D. protected long blipvert(int x) { return 0; } E. protected int blipvert(long x) { return 0; } F. protected long blipvert(long x) { return 0; } G. protected long blipvert(int x, int y) { return 0; }
A. public int blipvert(int x) { return 0; } C. private int blipvert(long x) { return 0; } E. protected int blipvert(long x) { return 0; } F. protected long blipvert(long x) { return 0; } G. protected long blipvert(int x, int y) { return 0; }
01. interface TestA { String toString(); } 02. 03. public class Test { 04. public static void main(String[] args) { 05. System.out.println(new TestA() { 06. public String toString() { return "test"; } 07. }); 08. } 09. } What is the result? A. test B. null C. An exception is thrown at runtime. D. Compilation fails because of an error in line 1. E. Compilation fails because of an error in line 5. F. Compilation fails because of an error in line 6.
A. test
Given: import java.util.*; public class Mapit { public static void main(String[] args) { Set<Integer> set = new HashSet<Integer>(); Integer i1 = 45; Integer i2 = 46; set.add(i1); set.add(i1); set.add(i2); System.out.print(set.size() + " "); set.remove(i1); System.out.print(set.size() + " "); i2 = 47; set.remove(i2); System.out.print(set.size() + " "); } } What is the result? A. 2 1 0 B. 2 1 1 C. 3 2 1 D. 3 2 2 E. Compilation fails. F. An exception is thrown at runtime.
B. 2 1 1
Given: int x = 0; int y = 10; do { y--; ++x; } while (x < 5); System.out.print(x + "," + y); What is the result? A. 5,6 B. 5,5 C. 6,5 D. 6,6
B. 5,5
Given: public class Batman { int squares = 81; public static void main(String[] args) { new Batman().go(); } void go() { incr(++squares); System.out.println(squares); } void incr(int squares) { squares += 10; } } What is the result? A. 81 B. 82 C. 91 D. 92 E. Compilation fails. F. An exception is thrown at runtime.
B. 82
public class Threads4 { public static void main (String[] args) { new Threads4().go(); } public void go() { Runnable r = new Runnable() { public void run() { System.out.print("foo"); } }; Thread t = new Thread(r); t.start(); t.start(); } } What is the result? A. Compilation fails. B. An exception is thrown at runtime. C. The code executes normally and prints "foo". D. The code executes normally, but nothing is printed.
B. An exception is thrown at runtime.
Given: interface Jumper { public void jump(); } class Animal {} class Dog extends Animal { Tail tail; } class Beagle extends Dog implements Jumper{ public void jump() {} } class Cat implements Jumper{ public void jump() {} } Which three are true? (Choose three.) A. Cat is-a Animal B. Cat is-a Jumper C. Dog is-a Animal D. Dog is-a Jumper E. Cat has-a Animal F. Beagle has-a Tail G. Beagle has-a Jumper
B. Cat is-a Jumper C. Dog is-a Animal F. Beagle has-a Tail
public static void parse(String str) { try { float f = Float.parseFloat(str); } catch (NumberFormatException nfe) { f = 0; } finally { System.out.println(f); } } public static void main(String[] args) { parse("invalid"); } What is the result? A. 0.0 B. Compilation fails. C. A ParseException is thrown by the parse method at runtime. D. A NumberFormatException is thrown by the parse method at runtime.
B. Compilation fails.
Given: 10. interface Foo {} 11. class Alpha implements Foo {} 12. class Beta extends Alpha {} 13. class Delta extends Beta { 14. public static void main( String[] args ) { 15. Beta x = new Beta(); 16. //insert code here 17. } 18. } Which code, inserted at line 16, will cause a java.lang.ClassCastException? A. Alpha a = x; B. Foo f = (Delta)x; C. Foo f = (Alpha)x; D. Beta b = (Beta)(Alpha)x;
B. Foo f = (Delta)x;
Given: 09. class Line { 10. public static class Point {} 11. } 12. 13. class Triangle { 14. public Triangle(){ 15. // insert code here 16. } 17. } Which code, inserted at line 15, creates an instance of the Point class defined in Line? A. Point p = new Point(); B. Line.Point p = new Line.Point(); C. The Point class cannot be instatiated at line 15. D. Line l = new Line(); l.Point p = new l.Point();
B. Line.Point p = new Line.Point();
A company has a business application that provides its users with many different reports: receivables reports, payables reports, revenue projects, and so on. The company has just purchased some new, stateof-the-art, wireless printers, and a programmer has been assigned the task of enhancing all of the reports to use not only the company's old printers, but the new wireless printers as well. When the programmer starts looking into the application, the programmer discovers that because of the design of the application, it is necessary to make changes to each report to support the new printers.Which two design concepts most likely explain this situation? (Choose two.) A. Inheritance B. Low cohesion C. Tight coupling D. High cohesion E. Loose coupling F. Object immutability
B. Low cohesion C. Tight coupling
01. public class Rainbow { 02. public enum MyColor { 03. RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff); 04. private final int rgb; 05. MyColor(int rgb) { this.rgb = rgb; } 06. public int getRGB() { return rgb; } 07. }; 08. public static void main(String[] args) { 09. //insert code here 10. } 11. } Which code fragment, inserted at line 9, allows the Rainbow class to compile? A. MyColor skyColor = BLUE; B. MyColor treeColor = MyColor.GREEN; C. if(RED.getRGB() < BLUE.getRGB()) { } D. Compilation fails due to other error(s) in the code.
B. MyColor treeColor = MyColor.GREEN;
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>();
B. Object o = list; C. String s = list.get(0); D. list = new ArrayList<String>();
Given: 31. //some code here line 31 32. try { 33. //some code here line 33 34. } catch (NullPointerException e1) { 35. //some code here line 35 36. } finally { 37. //some code here line 37 38. } Under which three circumstances will the code on line 37 be executed? (Choose three.) A. The instance gets garbage collected. B. The code on line 33 throws an exception. C. The code on line 35 throws an exception. D. The code on line 31 throws an exception. E. The code on line 33 executes successfully
B. The code on line 33 throws an exception. C. The code on line 35 throws an exception E. The code on line 33 executes successfully.
Given: 01. public class A{ 02. public void method1() { 03. try { 04. B b = new B(); 05. b.method2(); 06. //more code here 07. } catch (TestException te){ 08. throw new RuntimeException(te); 09. } 10. } 11. } 01. public class B{ 02. public void method2() throws TestException { 03. //more code here 04 } 05. } 01. class TestException extends Exception { 02. } 31. public void method() { 32. A a = new A(); 33. a.method1(); 34. } Which statement is true if a TestException is thrown on line 3 of class B? A. Line 33 must be called within a try block. B. The exception thrown by method1 in class A is not required to be caught. C. The method declared on line 31 must be declared to throw a RuntimeException. D. On line 5 of class A, the call to method2 of class B does not need to be placed in a try/catch block.
B. The exception thrown by method1 in class A is not required to be caught.
class PingPong2 { synchronized void hit(long n) { for(int i = 1; i < 3; i++) System.out.print(n + "-" + i + " "); } } public class Tester implements Runnable { static PingPong2 pp2 = new PingPong2(); public static void main(String[] args) { new Thread(new Tester()).start(); new Thread(new Tester()).start(); } public void run() { pp2.hit(Thread.currentThread().getId()); } } Which statement is true? A. The output could be 5-1 6-1 6-2 5-2 B. The output could be 6-1 6-2 5-1 5-2 C. The output could be 6-1 5-2 6-2 5-1 D. The output could be 6-1 6-2 5-1 7-1
B. The output could be 6-1 6-2 5-1 5-2
void waitForSignal() { Object obj = new Object(); synchronized (Thread.currentThread()) { obj.wait(); obj.notify(); } } Which statement is true? A. This code can throw an InterruptedException. B. This code can throw an IllegalMonitorStateException. C. This code can throw a TimeoutException after ten minutes. D. Reversing the order of obj.wait() and obj.notify() might cause this method to complete normally. E. A call to notify() or notifyAll() from another thread might cause this method to complete normally. F. This code does NOT compile unless "obj.wait()" is replaced with "((Thread) obj).wait()".
B. This code can throw an IllegalMonitorStateException.
A company that makes Computer Assisted Design (CAD) software has, within its application, some utility classes that are used to perform 3D rendering tasks. The company's chief scientist has just improved the performance of one of the utility classes' key rendering algorithms, and has assigned a programmer to replace the old algorithm with the new algorithm. When the programmer begins researching the utility classes, she is happy to discover that the algorithm to be replaced exists in only one class. The programmer reviews that class's API, and replaces the old algorithm with the new algorithm, being careful that her changes adhere strictly to the class's API. Once testing has begun, the programmer discovers that other classes that use the class she changed are no longer working properly. What design flaw is most likely the cause of these new bugs? A. Inheritance B. Tight coupling C. Low cohesion D. High cohesion E. Loose coupling F. Object immutability
B. Tight coupling
Given two files, GrizzlyBear.java and Salmon.java: 01. package animals.mammals; 02. 03. public class GrizzlyBear extends Bear { 04. void hunt() { 05. Salmon s = findSalmon(); 06. s.consume(); 07. } 08. } 01. package animals.fish; 02. 03. public class Salmon extends Fish { 04. public void consume() { /* do stuff */ } 05. } If both classes are in the correct directories for their packages, and the Mammal class correctly defines the findSalmon() method, which change allows this code to compile? A. add import animals.mammals.*; at line 2 in Salmon.java B. add import animals.fish.*; at line 2 in GrizzlyBear.java C. add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.java D. add import animals.mammals.GrizzlyBear.*; at line 2 in Salmon.java
B. add import animals.fish.*; at line 2 in GrizzlyBear.java
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 );
B. b = nf.format( input );
Which three code fragments, added individually at line 29, produce the output 100? (Choose three.) 10. class Inner { 11. private int x; 12. public void setX( int x ){ this.x = x; } 13. public int getX(){ return x;} 14. } 15. 16. class Outer { 17. private Inner y; 18. public void setY( Inner y ){ this.y = y; } 19. public Inner getY() { return y; } 20. } 21. 22. public class Gamma { 23. public static void main(String[] args) { 24. Outer o = new Outer(); 25. Inner i = new Inner(); 26. int n = 10; 27. i.setX(n); 28. o.setY(i); 29. // insert code here 30. System.out.println(o.getY().getX()); 31. } 32.} A. n = 100; B. i.setX( 100 ); C. o.getY().setX( 100 ); D. i = new Inner(); i.setX( 100 ); E. o.setY( i ); i = new Inner(); i.setX( 100 ); F. i = new Inner(); i.setX( 100 ); o.setY( i );
B. i.setX( 100 ); C. o.getY().setX( 100 ); F. i = new Inner(); i.setX( 100 ); o.setY( i );
Given: package com.company.application; public class MainClass { public static void main(String[] args) {} } and MainClass exists in the /apps/com/company/application directory. Assume the CLASSPATH environment variable is set to "." (current directory). Which two java commands entered at the command line will run MainClass? (Choose two.) A. java MainClass if run from the /apps directory B. java com.company.application.MainClass if run from the /apps directory C. java -classpath /apps com.company.application.MainClass if run from any directory D. java -classpath . MainClass if run from the /apps/com/company/application directory E. java -classpath /apps/com/company/application:. MainClass if run from the /apps directory F. java com.company.application.MainClass if run from the /apps/com/company/ application directory
B. java com.company. application.MainClass if run from the /apps directory C. java -classpath /apps com.company.application.MainClass if run from any directory
public abstract class Shape { private int x; private int y; public abstract void draw(); public void setAnchor(int x, int y) { this.x = x; this.y = y; } } Which two classes use the Shape class correctly? (Choose two.) A. public class Circle implements Shape { private int radius; } B. public abstract class Circle extends Shape { private int radius; } C. public class Circle extends Shape { private int radius; public void draw(); } D. public abstract class Circle implements Shape { private int radius; public void draw(); } E. public class Circle extends Shape { private int radius; public void draw() {/* code here */}
B. public abstract class Circle extends Shape { private int radius; } E. public class Circle extends Shape { private int radius; public void draw() {/* code here */}
. abstract public class Employee { 09. protected abstract double getSalesAmount(); 10. 11. public double getCommision() { 12. return getSalesAmount() * 0.15; 13. } 14. } 15 16. class Sales extends Employee { 17. // insert method here 18. } Which two methods, inserted independently at line 17, correctly complete the Sales class? (Choose two.) A. double getSalesAmount() { return 1230.45; } B. public double getSalesAmount() { return 1230.45; } C. private double getSalesAmount() { return 1230.45; } D. protected double getSalesAmount() { return 1230.45; }
B. public double getSalesAmount() { return 1230.45; } D. protected double getSalesAmount() { return 1230.45; }
Given: public class Score implements Comparable<Score> { private int wins, losses; public Score(int w, int l) { wins = w; losses = l; } public int getWins() { return wins; } public int getLosses() { return losses; } public String toString() { return "<" + wins + "," + losses + ">"; } // insert code here } 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*/}
B. public int compareTo(Score other){/*more code here*/}
Given: 34. HashMap props = new HashMap(); 35. props.put("key45", "some value"); 36. props.put("key12", "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);
B. s = new TreeSet(s);
Given: 09. class One { 10. void foo() { } 11. } 12. 13. class Two extends One { 14. //insert method here 15. } Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.) A. int foo() { /* more code here */ } B. void foo() { /* more code here */ } C. public void foo() { /* more code here */ } D. private void foo() { /* more code here */ } E. protected void foo() { /* more code here */ }
B. void foo() { /* more code here */ } C. public void foo() { /* more code here */ } E. protected void foo() { /* more code here */ }
A UNIX user named Bob wants to replace his chess program with a new one, but he is not sure where the old one is installed. Bob is currently able to run a Java chess program starting from his home directory / home/bob using the command: java -classpath /test:/home/bob/downloads/*.jar games.Chess Bob's CLASSPATH is set (at login time) to: /usr/lib:/home/bob/classes:/opt/java/lib:/opt/java/lib/*.jar What is a possible location for the Chess.class file? A. /test/Chess.class B. /home/bob/Chess.class C. /test/games/Chess.class D. /usr/lib/games/Chess.class E. /home/bob/games/Chess.class F. inside jarfile /opt/java/lib/Games.jar (with a correct manifest) G. inside jarfile /home/bob/downloads/Games.jar (with a correct manifest)
C. /test/games/Chess.class
Given: public void go() { String o = ""; z: for(int x = 0; x < 3; x++) { for(int y = 0; y < 2; y++) { if(x==1) break; if(x==2 && y==1) break z; o = o + x + y; } } System.out.println(o); } What is the result when the go() method is invoked? A. 00 B. 0001 C. 000120 D. 00012021 E. Compilation fails. F. An exception is thrown at runtime.
C. 000120
Given: 1. class X { 2. X() { System.out.print(1); } 3. 4. X(int x) { 5. this(); System.out.print(2); 6. } 7. } 8. 9. public class Y extends X { 10. Y() { super(6); System.out.print(3); } 11. 12. Y(int y) { 13. this(); System.out.println(4); 14. } 15. 16. public static void main(String[] a) { new Y(5); } 17.} What is the result? A. 13 B. 134 C. 1234 D. 2134 E. 2143 F. 4321
C. 1234
Given: import java.util.*; public class Quest { public static void main(String[] args) { String[] colors = {"blue", "red", "green", "yellow", "orange"}; Arrays.sort(colors); int s2 = Arrays.binarySearch(colors, "orange"); int s3 = Arrays.binarySearch(colors, "violet"); System.out.println(s2 + " " + s3); } } What is the result? A. 2 -1 B. 2 -4 C. 2 -5 D. 3 -1 E. 3 -4 F. 3 -5 G. Compilation fails. H. An exception is thrown at runtime.
C. 2 -5
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.
C. A ClassCastException occurs in line 29.
01. class Super { 02. private int a; 03. protected Super(int a) { this.a = a; } 04. } 11. class Sub extends Super { 12. public Sub(int a) { super(a); } 13. public Sub() { this.a = 5; } 14. } Which two, independently, will allow Sub to compile? (Choose two.) A. Change line 2 to: public int a; B. Change line 2 to: protected int a; C. Change line 13 to: public Sub() { this(5); } D. Change line 13 to: public Sub() { super(5); } E. Change line 13 to: public Sub() { super(a); }
C. Change line 13 to: public Sub() { this(5); } D. Change line 13 to: public Sub() { super(5); }
Given: 1. public class A { 2. public void doit() { 3. } 4. 5. public String doit() { 6. return "a"; 7. } 8. 9. public double doit(int x) { 10. return 1.0; 11. } 12.} What is the result? A. An exception is thrown at runtime. B. Compilation fails because of an error in line 9. C. Compilation fails because of an error in line 5. D. Compilation succeeds and no runtime errors with class A occur
C. Compilation fails because of an error in line 5.
Which statement is true about the classes and interfaces in the exhibit? 01. public interface A { 02. public void doSomething(String thing); 03. } 01. public class AImpl implements A { 02. public void doSomething(String msg) {} 03. } 01. public class B { 02. public A doit(){ 03. //more code here 04. } 05. public String execute(){ 06 //more code here 07 } 08. } 01. public class C extends B { 02. public AImpl doit(){ 03. //more code here 04. } 05. 06. public Object execute() { 07. //more code here 08. } 09. } 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 C will fail because of an error in line 6. D. Compilation of class AImpl will fail because of an error in line 2.
C. Compilation of class C will fail because of an error in line 6.
05. class Building { } 06. public class Barn extends Building { 07. public static void main(String[] args) { 08. Building build1 = new Building(); 09. Barn barn1 = new Barn(); 10. Barn barn2 = (Barn) build1; 11. Object obj1 = (Object) build1; 12. String str1 = (String) build1; 13. Building build2 = (Building) barn1; 14. } 15. } Which is true? A. If line 10 is removed, the compilation succeeds. B. If line 11 is removed, the compilation succeeds. C. If line 12 is removed, the compilation succeeds. D. If line 13 is removed, the compilation succeeds. E. More than one line must be removed for compilation to succeed.
C. If line 12 is removed, the compilation succeeds.
Given the following directory structure: bigProject |--source | |--Utils.java | |--classes And the following command line invocation: javac -d classes source/Utils.java Assume the current directory is bigProject, what is the result? A. If the compile is successful, Utils.class is added to the source directory. B. The compiler returns an invalid flag error. C. If the compile is successful, Utils.class is added to the classes directory. D. If the compile is successful, Utils.class is added to the bigProject directory.
C. If the compile is successful, Utils.class is added to the classes directory.
Which statement is true? A. A class's finalize() method CANNOT be invoked explicitly. B. super.finalize() is called implicitly by any overriding finalize() method. C. The finalize() method for a given object is called no more than once by the garbage collector. D. The order in which finalize() is called on two objects is based on the order in which the two objects became finalizable.
C. The finalize() method for a given object is called no more than once by the garbage collector.
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.
C. The hashCode method for a given class can be used to test for object inequality, but NOT object equality, for that class. 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.
package test; class Target { public String name = "hello"; } What can directly access and change the value of the variable name? A. any class B. only the Target class C. any class in the test package D. any class that extends Target
C. any class in the test package
Given: public class Donkey2 { public static void main(String[] args) { boolean assertsOn = true; assert (assertsOn) : assertsOn = true; if(assertsOn) { System.out.println("assert is on"); } } } If class Donkey is invoked twice, the first time without assertions enabled, and the second time with assertions enabled, what are the results? A. no output B. no output assert is on C. assert is on D. no output An AssertionError is thrown. E. assert is on An AssertionError is thrown
C. assert is on
Given: 09. interface Foo { int bar(); } 10. 11. public class Sprite { 12. public int fubar( Foo foo ) { return foo.bar(); } 13. public void testFoo() { 14. fubar( 15. //insert code here 15 16. ); 17. } 18. } Which code, inserted at line 15, allows the class Sprite to compile? A. Foo { public int bar() { return 1; } B. new Foo { public int bar() { return 1; } C. new Foo() { public int bar() { return 1; } D. new class Foo { public int bar() { return 1; }
C. new Foo() { public int bar() { return 1; }
Which three will compile and run without exception? (Choose three.) A. private synchronized Object o; B. void go() { synchronized() { /* code here */ } } C. public synchronized void go() { /* code here */ } D. private synchronized(this) void go() { /* code here */ } E. void go() { synchronized(Object.class) { /* code here */ } } F. void go() { Object o = new Object(); synchronized(o) { /* code here */ }
C. public synchronized void go() { /* code here */ } E. void go() { synchronized(Object.class) { /* code here */ } } F. void go() { Object o = new Object(); synchronized(o) { /* code here */ }
Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given: 13. import java.io.*; 14. class Food implements Serializable {int good = 3;} 15. class Fruit extends Food {int juice = 5;} 16. public class Banana extends Fruit { 17. int yellow = 4; 18. public static void main(String [] args) { 19. Banana b = new Banana(); Banana b2 = new Banana(); 20. b.serializeBanana(b); // assume correct serialization 21. b2 = b.deserializeBanana(); // assume correct 22. System.out.println("restore "+b2.yellow+ b2.juice+b2.good); 24. } 25. // more Banana methods go here 50. } What is the result? A. restore 400 B. restore 403 C. restore 453 D. Compilation fails. E. An exception is thrown at runtime
C. restore 453
Given a valid 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. d = df.parse(ds); B. d = df.getDate(ds); C. try { d = df.parse(ds); } catch(ParseException e) { }; D. try { d = df.getDate(ds); } catch(ParseException e) { };
C. try { d = df.parse(ds); } catch(ParseException e) { };
Given classes defined in two different files: package util; public class BitUtils { public static void process(byte[] b) { /* more code here */ } } 1. package app; 2. 3. public class SomeApp { 4. public static void main(String[] args) { 5. byte[] bytes = new byte[256]; 6. // insert code here 7. } 8. } What is required at line 6 in class SomeApp to use the process method of BitUtils? A. process(bytes); B. BitUtils.process(bytes); C. util.BitUtils.process(bytes); D. SomeApp cannot use methods in BitUtils. E. import util.BitUtils.*; process(bytes);
C. util.BitUtils.process(bytes);
11. abstract class Vehicle { public int speed() { return 0; } 12. class Car extends Vehicle { public int speed() { return 60; } 13. class RaceCar extends Car { public int speed() { return 150; } ... 21. RaceCar racer = new RaceCar(); 22. Car car = new RaceCar(); 23 Vehicle vehicle = new RaceCar(); 24 System.out.println(racer.speed() + ", " + car.speed() + ", " + vehicle.speed()); What is the result? A. 0, 0, 0 B. 150, 60, 0 C. Compilation fails. D. 150, 150, 150 E. An exception is thrown at runtime.
D. 150, 150, 150
Given: 11. public class Test { 12. public static void main(String [] args) { 13. int x = 5; 14. boolean b1 = true; 15. boolean b2 = false; 16. 17. if ((x == 4) && !b2 ) 18. System.out.print("1 "); 19. System.out.print("2 "); 20. if ((b2 = true) && b1 ) 21. System.out.print("3 "); 22. } 23. } What is the result? A. 2 B. 3 C. 1 2 D. 2 3 E. 1 2 3 F. Compilation fails.
D. 2 3
Given: 01. public class Mud { 02. //insert code here 03. System.out.println("hi"); 04. } 05. } And the following five fragments: public static void main(String...a) { public static void main(String.* a) { public static void main(String... a) { public static void main(String[]... a) { public static void main(String...[] a) { How many of the code fragments, inserted independently at line 2, compile? A. 0 B. 1 C. 2 D. 3 E. 4 F. 5
D. 3
Given: import java.util.*; public class WrappedString { private String s; public WrappedString(String s) { this.s = s; } public static void main(String[] args) { HashSet<Object> hs = new HashSet<Object>(); WrappedString ws1 = new WrappedString("aardvark"); WrappedString ws2 = new WrappedString("aardvark"); String s1 = new String("aardvark"); String s2 = new String("aardvark"); hs.add(ws1); hs.add(ws2); hs.add(s1); hs.add(s2); System.out.println(hs.size()); } } What is the result? A. 0 B. 1 C. 2 D. 3 E. 4 F. Compilation fails. G. An exception is thrown at runtime
D. 3
Given: 01. public class Boxer1{ 02. Integer i; 03. int x; 04. public Boxer1(int y) { 05. x = i+y; 06. System.out.println(x); 07. } 08. public static void main(String[] args) { 09. 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. F. An IllegalStateException occurs at runtime.
D. A NullPointerException occurs at runtime.
Given: public class ClassA { public void methodA() { ClassB classB = new ClassB(); classB.getValue(); } } class ClassB { public ClassC classC; public String getValue() { return classC.getValue(); } } class ClassC { public String value; public String getValue() { value = "ClassB"; return value; } } and: ClassA a = new ClassA(); a.methodA(); What is the result? A. Compilation fails. B. ClassC is displayed. C. The code runs with no output. D. An exception is thrown at runtime.
D. An exception is thrown at runtime.
What is the result? 11. public class Person { 12. String name = "No name"; 13. public Person(String nm) { name = nm; } 14. } 15. 16. public class Employee extends Person { 17. String empID = "0000"; 18. public Employee(String id) { empID = id; } 19. } 20. 21. public class EmployeeTest { 22. public static void main(String[] args){ 23. Employee e = new Employee("4321"); 24. System.out.println(e.empID); 25. } 26. } A. 4321 B. 0000 C. An exception is thrown at runtime. D. Compilation fails because of an error in line 18
D. Compilation fails because of an error in line 18
public class Barn { public static void main(String[] args) { new Barn().go("hi", 1); new Barn().go("hi", "world", 2); } public void go(String... y, int x) { System.out.print(y[y.length - 1] + " "); } } What is the result? A. hi hi B. hi world C. world world D. Compilation fails. E. An exception is thrown at runtime
D. Compilation fails.
public class Threads2 implements Runnable { public void run() { System.out.println("run."); throw new RuntimeException("Problem"); } public static void main(String[] args) { Thread t = new Thread(new Threads2()); t.start(); System.out.println("End of method."); } } Which two can be results? (Choose two.) A. java.lang.RuntimeException: Problem B. run. java.lang.RuntimeException: Problem C. End of method. java.lang.RuntimeException: Problem D. End of method. run. java.lang.RuntimeException: Problem E. run. java.lang.RuntimeException: Problem End of method.
D. End of method. run. java.lang.RuntimeException: Problem E. run. java.lang.RuntimeException: Problem End of method.
Given: String[] elements = { "for", "tea", "too" }; String first = (elements.length > 0) ? elements[0] : null; What is the result? A. Compilation fails. B. An exception is thrown at runtime. C. The variable first is set to null. D. The variable first is set to elements[0].
D. The variable first is set to elements[0].
Which capability exists only in java.io.FileWriter? A. Closing an open stream. B. Flushing an open stream. C. Writing to an open stream. D. Writing a line separator to an open stream.
D. Writing a line separator to an open stream.
Given: 33. try { 34. //some code here 35. } catch (NullPointerException e1) { 36. System.out.print("a"); 37. } catch (Exception e2) { 38. System.out.print("b"); 39. } finally { 40. System.out.print("c"); 41. } If some sort of exception is thrown at line 34, which output is possible? A. a B. b C. c D. ac E. abc
D. ac
Given that the elements of a PriorityQueue are ordered according to natural ordering, and: import java.util.*; public class GetInLine { public static void main(String[] args) { PriorityQueue<String> pq = new PriorityQueue<String>(); pq.add("banana"); pq.add("pear"); pq.add("apple"); System.out.println(pq.poll() + " " + pq.peek()); } } What is the result? A. apple pear B. banana pear C. apple apple D. apple banana E. banana banana
D. apple banana
QUESTION 18 Which Man class properly represents the relationship "Man has a best friend who is a Dog"? A. class Man extends Dog { } B. class Man implements Dog { } C. class Man { private BestFriend dog; } D. class Man { private Dog bestFriend; } E. class Man { private Dog<bestFriend>; } F. class Man { private BestFriend<dog>; }
D. class Man { private Dog bestFriend; }
Given: public class Pass { public static void main(String [] args) { int x = 5; Pass p = new Pass(); p.doStuff(x); System.out.print(" main x = " + x); } void doStuff(int x) { System.out.print(" doStuff x = " + x++); } } What is the result? A. Compilation fails. B. An exception is thrown at runtime. C. doStuff x = 6 main x = 6 D. doStuff x = 5 main x = 5 E. doStuff x = 5 main x = 6 F. doStuff x = 6 main x = 5
D. doStuff x = 5 main x = 5
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> {
D. public class MinMax<N extends Number> { F. public class MinMax<N extends Integer> {
Given: static void test() throws RuntimeException { try { System.out.print("test "); throw new RuntimeException(); } catch (Exception ex) { System.out.print("exception "); } } public static void main(String[] args) { try { test(); } catch (RuntimeException ex) { System.out.print("runtime "); } System.out.print("end "); } What is the result? A. test end B. Compilation fails. C. test runtime end D. test exception end E. A Throwable is thrown by main at runtime.
D. test exception end
Which code, inserted at line 14, will allow this class to correctly serialize and deserialize? 01. import java.io.*; 02. public class Foo implements Serializable { 03. public int x, y; 04. public Foo(int x, int y){ 05. this.x = x; this.y = y; 06. } 07. 08. private void writeObject(ObjectOutputStream s) 09. throws IOException{ 10. s.writeInt(x); s.writeInt(y); 11. } 12. 13. private void readObject(ObjectInputStream s) 14. throws IOException, ClassNotFoundException { 15. //insert code here 16. } 17. } A. s.defaultReadObject(); B. this = s.defaultReadObject(); C. y = s.readInt(); x = s.readInt(); D. x = s.readInt(); y = s.readInt();
D. x = s.readInt(); y = s.readInt();
Given: 01. interface Animal { void makeNoise(); } 02. class Horse implements Animal { 03. Long weight = 1200L; 04. public void makeNoise() { System.out.println("whinny"); } 05. } 06. 07. public class Icelandic extends Horse { 08. public void makeNoise() { System.out.println("vinny"); } 09. public static void main(String[] args) { 10. Icelandic i1 = new Icelandic(); 11. Icelandic i2 = new Icelandic(); 12. Icelandic i3 = new Icelandic(); 13. i3 = i1; i1 = i2; i2 = null; i3 = i1; 14. } 15. } When line 14 is reached, how many objects are eligible for the garbage collector? A. 0 B. 1 C. 2 D. 3 E. 4 F. 6
E. 4
Given: 10. public class SuperCalc { 11. protected static int multiply(int a, int b) { return a * b;} 12. } and: 20. public class SubCalc extends SuperCalc{ 21. public static int multiply(int a, int b) { 22. int c = super.multiply(a, b); 23. return c; 24. } 25. } and: 30. SubCalc sc = new SubCalc (); 31. System.out.println(sc.multiply(3,4)); 32. System.out.println(SubCalc.multiply(2,2)); What is the result? A. 12 B. The code runs with no output. C. An exception is thrown at runtime. D. Compilation fails because of an error in line 21. E. Compilation fails because of an error in line 22. F. Compilation fails because of an error in line 31.
E. Compilation fails because of an error in line 22.
21. class Money { 22. private String country = "Canada"; 23. public String getC() { return country; } 24. } 25. class Yen extends Money { 26. public String getC() { return super.country; } 27. } 28. public class Euro extends Money { 29. public String getC(int x) { return super.getC(); } 30. public static void main(String[] args) { 31. System.out.print(new Yen().getC() + " " + new Euro().getC()); 32. } 33. } What is the result? A. Canada B. null Canada C. Canada null D. Canada Canada E. Compilation fails due to an error on line 26. F. Compilation fails due to an error on line 29.
E. Compilation fails due to an error on line 26.
Given that t1 is a reference to a live thread, which is true? A. The Thread.sleep() method can take t1 as an argument. B. The Object.notify() method can take t1 as an argument. C. The Thread.yield() method can take t1 as an argument. D. The Thread.setPriority() method can take t1 as an argument. E. The Object.notify() method arbitrarily chooses which thread to notify
E. The Object.notify() method arbitrarily chooses which thread to notify
Given: public class TestOne implements Runnable { public static void main (String[] args) throws Exception { Thread t = new Thread(new TestOne()); t.start(); System.out.print("Started"); t.join(); System.out.print("Complete"); } public void run() { for (int i = 0; i < 4; i++) { System.out.print(i); } } } What can be a result? A. Compilation fails. B. An exception is thrown at runtime. C. The code executes and prints "StartedComplete". D. The code executes and prints "StartedComplete0123". E. The code executes and prints "Started0123Complete".
E. The code executes and prints "Started0123Complete".
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"); F. sb1.concat("abc"); s1 = s1.concat("abc"); G. sb1.append("abc"); s1 = s1 + s1.concat("abc"); H. sb1.concat("abc"); s1 = s1 + s1.concat("abc");
E. sb1.append("abc"); s1 = s1.concat("abc");
Given: import java.util.*; public class Explorer1 { public static void main(String[] args) { TreeSet<Integer> s = new TreeSet<Integer>(); TreeSet<Integer> subs = new TreeSet<Integer>(); for(int i = 606; i < 613; i++) if(i%2 == 0) s.add(i); subs = (TreeSet)s.subSet(608, true, 611, true); s.add(609); System.out.println(s + " " + subs); } } What is the result? A. Compilation fails. B. An exception is thrown at runtime. C. [608, 609, 610, 612] [608, 610] D. [608, 609, 610, 612] [608, 609, 610] E. [606, 608, 609, 610, 612] [608, 610] F. [606, 608, 609, 610, 612] [608, 609, 610]
F. [606, 608, 609, 610, 612] [608, 609, 610]
class Atom { Atom() { System.out.print("atom "); } } class Rock extends Atom { Rock(String type) { System.out.print(type); } } public class Mountain extends Rock { Mountain() { super("granite "); new Rock("granite "); } public static void main(String[] a) { new Mountain(); } } What is the result? A. Compilation fails. B. atom granite C. granite granite D. atom granite granite E. An exception is thrown at runtime F. atom granite atom granite
F. atom granite atom granite
Given a class Repetition: package utils; public class Repetition { public static String twice(String s) { return s + s; } } and given another class Demo: 01. public class Demo { 02. public static void main(String[] args) { 03. System.out.println(twice("pizza")); 04. } 05. } Which code should be inserted at line 1 of Demo.java to compile and run Demo to print "pizzapizza"? A. import utils.*; B. static import utils.*; C. import utils.Repetition.*; D. static import utils.Repetition.*; E. import utils.Repetition.twice(); F. import static utils.Repetition.twice; G. static import utils.Repetition.twice;
F. import static utils.Repetition.twice;
Click the Exhibit button. Given the fully-qualified class names: com.foo.bar.Dog com.foo.bar.blatz.Book com.bar.Car com.bar.blatz.Sun Which graph represents the correct directory structure for a JAR file from which those classes can be used by the compiler and JVM?
JAR A