1Z0-809 | A Review Of Free 1Z0-809 practice test


Q1. Given the code fragment: 

List<String> empDetails = Arrays.asList(“100, Robin, HR”, 

“200, Mary, AdminServices”, 

“101, Peter, HR”); 

empDetails.stream() 

.filter(s-> s.contains(“1”)) 

.sorted() 

.forEach(System.out::println); //line n1 

What is the result? 

A. 100, Robin, HR 101, Peter, HR 

B. E. A compilation error occurs at line n1. 

C. 100, Robin, HR 101, Peter, HR 200, Mary, AdminServices 

D. 100, Robin, HR 200, Mary, AdminServices 101, Peter, HR 

Answer:

Q2. Given that course.txt is accessible and contains: 

Course : : Java 

and given the code fragment: 

public static void main (String[ ] args) { 

int i; 

char c; 

try (FileInputStream fis = new FileInputStream (“course.txt”); 

InputStreamReader isr = new InputStreamReader(fis);) { 

while (isr.ready()) { //line n1 

isr.skip(2); 

i = isr.read (); 

c = (char) i; 

System.out.print(c); 

} catch (Exception e) { 

e.printStackTrace(); 

What is the result? 

A. ur :: va 

B. ueJa 

C. The program prints nothing. 

D. A compilation error occurs at line n1. 

Answer:

Q3. Given: 

class Bird { 

public void fly () { System.out.print(“Can fly”); } 

class Penguin extends Bird { 

public void fly () { System.out.print(“Cannot fly”); } 

and the code fragment: 

class Birdie { 

public static void main (String [ ] args) { 

fly( ( ) -> new Bird ( )); 

fly (Penguin : : new); 

/* line n1 */ 

Which code fragment, when inserted at line n1, enables the Birdie class to compile? 

A. static void fly (Consumer<Bird> bird) { 

bird :: fly (); } 

B. static void fly (Consumer<? extends Bird> bird) { 

bird.accept( ) fly (); 

C. static void fly (Supplier<Bird> bird) { 

bird.get( ) fly (); 

D. static void fly (Supplier<? extends Bird> bird) { 

LOST 

Answer:

Explanation: NOTE: Very confusing question. There is no logic in the options. 

Q4. Given the class definitions: 

And the code fragment of the main() method, 

What is the result? 

A. Java Java Java 

B. Java Jeve va 

C. Java Jeve ve 

D. Compilation fails 

Answer:

Q5. Given: 

public class Test<T> { 

private T t; 

public T get () { 

return t; 

public void set (T t) { 

this.t = t; 

public static void main (String args [ ] ) { 

Test<String> type = new Test<>(); 

Test type 1 = new Test ();//line n1 

type.set(“Java”); 

type1.set(100);//line n2 

System.out.print(type.get() + “ “ + type1.get()); 

What is the result? 

A. Java 100 

B. java.lang.string@<hashcode>java.lang.Integer@<hashcode> 

C. A compilation error occurs. To rectify it, replace line n1 with: Test<Integer> type1 = new Test<>(); 

D. A compilation error occurs. To rectify it, replace line n2 with: type1.set (Integer(100)); 

Answer:

Q6. The protected modifier on a Field declaration within a public class means that the field ______________. 

A. Cannot be modified 

B. Can be read but not written from outside the class 

C. Can be read and written from this class and its subclasses only within the same package 

D. Can be read and written from this class and its subclasses defined in any package 

Answer:

Reference: 

http://beginnersbook.com/2013/05/java-access-modifiers/ 

Q7. Given: 

public class Foo<K, V> { 

private K key; 

private V value; 

public Foo (K key, V value) (this.key = key; this value = value;) 

public static <T> Foo<T, T> twice (T value) (return new Foo<T, T> (value, value); ) 

public K getKey () (return key;) 

public V getValue () (return value;) 

Which option fails? 

A. Foo<String, Integer> mark = new Foo<String, Integer> (“Steve”, 100); 

B. Foo<String, String> pair = Foo.<String>twice (“Hello World!”); 

C. Foo<?, ?> percentage = new Foo <> (97, 32); 

D. Foo<String, String> grade = new Foo <> (“John”, “A”); 

Answer:

Q8. Given the code fragment: 

List<Integer> values = Arrays.asList (1, 2, 3); 

values.stream () 

.map(n -> n*2)//line n1 

.peek(System.out::print)//line n2 

.count(); 

What is the result? 

A. 246 

B. The code produces no output. 

C. A compilation error occurs at line n1. 

D. A compilation error occurs at line n2. 

Answer:

Q9. Given: What is the result? 

A. 0 Done 

B. First Exception Done 

C. Second Exception 

D. Done Third Exception 

E. Third Exception 

Answer:

Q10. Given: 

public class Canvas implements Drawable { 

public void draw () { } 

public abstract class Board extends Canvas { } 

public class Paper extends Canvas { 

protected void draw (int color) { } 

public class Frame extends Canvas implements Drawable { 

public void resize () { } 

public interface Drawable { 

public abstract void draw (); 

Which statement is true? 

A. Board does not compile. 

B. Paper does not compile. 

C. Frame does not compile. 

D. Drawable does not compile. 

E. All classes compile successfully. 

Answer: