About Question enthuware.ocpjp.v8.2.1875 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
surzhin
Posts: 7
Joined: Fri Dec 11, 2015 6:50 am
Contact:

About Question enthuware.ocpjp.v8.2.1875 :

Post by surzhin »

1. There isn’t a field with name "author" in the class Book. ;)
2.
public class TestClass {

public static void main(String[] args) {
List<Book> books = getBooksByAuthor("Ludlum");
books.stream().sorted().forEach(b -> System.out.println(b.getIsbn()));
}

private static List<Book> getBooksByAuthor(String ludlum) {
List<Book> al = new ArrayList<>();
al.add(new Book("123", "Big Bang"));
return al;
}
}

It will no throw a ClassCastException and print "123".

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1875 :

Post by admin »

surzhin wrote:1. There isn’t a field with name "author" in the class Book. ;)
That is ok. The problem statement asks you to assume that getBooksByAuthor is a valid method that returns a List of Books. This method might return the list of books through some other means (not necessarily by looking at a field of the class).
2.
public class TestClass {

public static void main(String[] args) {
List<Book> books = getBooksByAuthor("Ludlum");
books.stream().sorted().forEach(b -> System.out.println(b.getIsbn()));
}

private static List<Book> getBooksByAuthor(String ludlum) {
List<Book> al = new ArrayList<>();
al.add(new Book("123", "Big Bang"));
return al;
}
}

It will no throw a ClassCastException and print "123".
getBooksByAuthor returns a List of Books (plural). So it could contain more than one book.

HTH,
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests