1z0-809 Practice Test Questions

128 Questions


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.





A.
  

Compilation fails.



Which statement is true about the single abstract method of the java.util.function.Function
interface?


A.

It accepts one argument and returns void.


B.

It accepts one argument and returns boolean.


C.

It accepts one argument and always produces a result of the same type as the
argument.


D.

It accepts an argument and produces a result of any data type





C.
  

It accepts one argument and always produces a result of the same type as the
argument.



Reference: http://winterbe.com/posts/2014/03/16/java-8-tutorial/ (functions)

Given:
public final class IceCream {
public void prepare() {}
}
public class Cake {
public final void bake(int min, int temp) {}
public void mix() {}
}
public class Shop {
private Cake c = new Cake ();
private final double discount = 0.25;
public void makeReady () { c.bake(10, 120); }
}
public class Bread extends Cake {
public void bake(int minutes, int temperature) {}
public void addToppings() {}
Which statement is true?


A.

A compilation error occurs in IceCream.


B.

A compilation error occurs in Cake.


C.

A compilation error occurs in Shop.


D.

A compilation error occurs in Bread


E.

All classes compile successfully.





D.
  

A compilation error occurs in Bread



Given:

What is the result?


A.

Marrown
String out of limits
JesOran


B.

Marrown
String out of limits
Array out of limits


C.

Marrown
String out of limits


D.

Marrown
NanRed
JesOran





A.
  

Marrown
String out of limits
JesOran



Given the code fragment:
int b = 3;
if ( !(b > 3)) {
System.out.println("square ");
}{
System.out.println("circle ");
}
System.out.println("...");
What is the result?


A.

square...


B.

circle...


C.

squarecircle...


D.

Compilation fails.





C.
  

squarecircle...



Given the code fragment:


What is the result?


A.

20


B.

25


C.

29


D.

Compilation fails


E.

AnArrayIndexOutOfBoundsException is thrown at runtime





A.
  

20



Given:
public class Emp {
String fName;
String lName;
public Emp (String fn, String ln) {
fName = fn;
lName = ln;
}
public String getfName() { return fName; }
public String getlName() { return lName; }
}
and the code fragment:
List<Emp> emp = Arrays.asList (
new Emp (“John”, “Smith”),
new Emp (“Peter”, “Sam”),
new Emp (“Thomas”, “Wale”));
emp.stream()
//line n1
.collect(Collectors.toList());
Which code fragment, when inserted at line n1, sorts the employees list in descending
order of fName and then ascending order of lName?


A.

sorted
(Comparator.comparing(Emp::getfName).reserved().thenComparing(Emp::getlName))


B.

sorted (Comparator.comparing(Emp::getfName).thenComparing(Emp::getlName))


C.

map(Emp::getfName).sorted(Comparator.reserveOrder())


D.

map(Emp::getfName).sorted(Comparator.reserveOrder().map(Emp::getlName).reserved





A.
  

sorted
(Comparator.comparing(Emp::getfName).reserved().thenComparing(Emp::getlName))



Given the code fragments:
public class Book implements Comparator<Book> {
String name;
double price;
public Book () {}
public Book(String name, double price) {
this.name = name;
this.price = price;
}
public int compare(Book b1, Book b2) {
return b1.name.compareTo(b2.name);
}
public String toString() {
return name + “:” + price;
}
}
and
List<Book>books = Arrays.asList (new Book (“Beginning with Java”, 2), new book (“A
Guide to Java Tour”, 3));
Collections.sort(books, new Book());
System.out.print(books);
What is the result?


A.

[A Guide to Java Tour:3, Beginning with Java:2]


B.

[Beginning with Java:2, A Guide to Java Tour:3]


C.

A compilation error occurs because the Book class does not override the abstract
method compareTo().


D.

An Exception is thrown at run time.





A.
  

[A Guide to Java Tour:3, Beginning with Java:2]



Given the class definitions:

What is the result?


A.

Java
Java
Java


B.

Java
Jeve
va


C.

Java
Jeve
ve


D.

Compilation fails





D.
  

Compilation fails



Given:

What is the result?


A.

hEllOjAvA!


B.

Hello java!


C.

Out of limits
hEllOjAvA!


D.

Out of limits





C.
  

Out of limits
hEllOjAvA!



Given the code fragment:
BiFunction<Integer, Double, Integer> val = (t1, t2) -> t1 + t2;//line n1
System.out.println(val.apply(10, 10.5));
What is the result?


A.

20


B.

20.5


C.

A compilation error occurs at line n1.


D.

A compilation error occurs at line n2.





C.
  

A compilation error occurs at line n1.



Given:
Book.java:
public class Book {
private String read(String bname) { return “Read” + bname }
}
EBook.java:
public class EBook extends Book {
public class String read (String url) { return “View” + url }
}
Test.java:
public class Test {
public static void main (String[] args) {
Book b1 = new Book();
b1.read(“Java Programing”);
Book b2 = new EBook();
b2.read(“http://ebook.com/ebook”);
What is the result?


A.

Read Java Programming
View http:/ ebook.com/ebook


B.

Read Java Programming
Read http:/ ebook.com/ebook


C.

The EBook.java file fails to compile.


D.

The Test.java file fails to compile.





D.
  

The Test.java file fails to compile.




Page 4 out of 11 Pages
Previous