1Z0-809 | A Review Of Breathing 1Z0-809 pdf


Q31. Given the code fragment: 

List<String> listVal = Arrays.asList(“Joe”, “Paul”, “Alice”, “Tom”); 

System.out.println ( 

// line n1 

); 

Which code fragment, when inserted at line n1, enables the code to print the count of string elements whose length is greater than three? 

A. listVal.stream().filter(x -> x.length()>3).count() 

B. listVal.stream().map(x -> x.length()>3).count() 

C. listVal.stream().peek(x -> x.length()>3).count().get() 

D. listVal.stream().filter(x -> x.length()>3).mapToInt(x -> x).count() 

Answer:

Q32. Given the code fragments: 

4. 

void doStuff() throws ArithmeticException, NumberFormatException, Exception { 

5. 

if (Math.random() >-1 throw new Exception (“Try again”); 

6. 

} and 

24. 

try { 

25. 

doStuff ( ): 

26. 

} catch (ArithmeticException | NumberFormatException | Exception e) { 

27. 

System.out.println (e.getMessage()); } 

28. 

catch (Exception e) { 

29. 

System.out.println (e.getMessage()); } 

30. 

Which modification enables the code to print Try again? 

A. Comment the lines 28, 29 and 30. 

B. Replace line 26 with: 

} catch (Exception | ArithmeticException | NumberFormatException e) { 

C. Replace line 26 with: 

} catch (ArithmeticException | NumberFormatException e) { 

D. Replace line 27 with: 

throw e; 

Answer:

Q33. Given: 

class ImageScanner implements AutoCloseable { 

public void close () throws Exception { 

System.out.print (“Scanner closed.”); 

public void scanImage () throws Exception { 

System.out.print (“Scan.”); 

throw new Exception(“Unable to scan.”); 

class ImagePrinter implements AutoCloseable { 

public void close () throws Exception { 

System.out.print (“Printer closed.”); 

public void printImage () {System.out.print(“Print.”); } 

and this code fragment: 

try (ImageScanner ir = new ImageScanner(); 

ImagePrinter iw = new ImagePrinter()) { 

ir.scanImage(); 

iw.printImage(); 

} catch (Exception e) { 

System.out.print(e.getMessage()); 

What is the result? 

A. Scan.Printer closed. Scanner closed. Unable to scan. 

B. Scan.Scanner closed. Unable to scan. 

C. Scan. Unable to scan. 

D. Scan. Unable to scan. Printer closed. 

Answer:

Q34. A method is declared to take three arguments. A program calls this method and passes only two arguments. What is the results? 

A. Compilation fails. 

B. The third argument is given the value null. 

C. The third argument is given the value void. 

D. The third argument is given the value zero. 

E. The third argument is given the appropriate falsy value for its declared type. F) An exception occurs when the method attempts to access the third argument. 

Answer:

Q35. Which three statements are benefits of encapsulation? 

A. Allows a class implementation to change without changing t he clients 

B. Protects confidential data from leaking out of the objects 

C. Prevents code from causing exceptions 

D. Enables the class implementation to protect its invariants 

E. Permits classes to be combined into the same package 

F. Enables multiple instances of the same class to be created safely 

Answer: A,B,D 

Q36. Given: 

class CheckClass { 

public static int checkValue (String s1, String s2) { 

return s1 length() – s2.length(); 

and the code fragment: 

String[] strArray = new String [] {“Tiger”, “Rat”, “Cat”, “Lion”} 

//line n1 

for (String s : strArray) { 

System.out.print (s + “ “); 

Which code fragment should be inserted at line n1 to enable the code to print Rat Cat Lion Tiger? 

A. Arrays.sort(strArray, CheckClass : : checkValue); 

B. Arrays.sort(strArray, (CheckClass : : new) : : checkValue); 

C. Arrays.sort(strArray, (CheckClass : : new).checkValue); 

D. Arrays.sort(strArray, CheckClass : : new : : checkValue); 

Answer:

Q37. Given the code fragments: 

class TechName { 

String techName; 

TechName (String techName) { 

this.techName=techName; 

and 

List<TechName> tech = Arrays.asList ( 

new TechName(“Java-“), 

new TechName(“Oracle DB-“), 

new TechName(“J2EE-“) 

); 

Stream<TechName> stre = tech.stream(); 

//line n1 

Which should be inserted at line n1 to print Java-Oracle DB-J2EE-? 

A. stre.forEach(System.out::print); 

B. stre.map(a-> a.techName).forEach(System.out::print); 

C. stre.map(a-> a).forEachOrdered(System.out::print); 

D. stre.forEachOrdered(System.out::print); 

Answer:

Q38. Given: 

class Vehicle { 

int vno; 

String name; 

public Vehicle (int vno, String name) { 

this.vno = vno,; 

this.name = name; 

public String toString () { 

return vno + “:” + name; 

and this code fragment: 

Set<Vehicle> vehicles = new TreeSet <> (); 

vehicles.add(new Vehicle (10123, “Ford”)); 

vehicles.add(new Vehicle (10124, “BMW”)); 

System.out.println(vehicles); 

What is the result? 

A. 10123 Ford 10124 BMW 

B. 10124 BMW 10123 Ford 

C. A compilation error occurs. 

D. A ClassCastException is thrown at run time. 

Answer:

Q39. Which two items can legally be contained within a java class declaration? 

A. An import statement 

B. A field declaration 

C. A package declaration 

D. A method declaration 

Answer: B,D 

Reference: 

http://docs.oracle.com/javase/tutorial/java/javaOO/methods.html 

Q40. Given: 

Class A { } Class B { } Interface X { } 

Interface Y { } 

Which two definitions of class C are valid? 

A. Class C extends A implements X { } 

B. Class C implements Y extends B { } 

C. Class C extends A, B { } 

D. Class C implements X, Y extends B { } 

E. Class C extends B implements X, Y { } 

Answer: A,E 

Explanation: extends is for extending a class. 

implements is for implementing an interface. Java allows for a class to implement many interfaces.