Oracle
1Z0-809 · Question #241
1Z0-809 Question #241: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-809 to reveal the answer and full explanation for question #241. The question stem and answer options stay visible for context.
Question
Given:
class Person {
private String firstName;
private int salary;
public Person(String fN, int sal) {
this.firstName = fN;
this.salary = sal;
}
public int getSalary() { return salary; }
public String getFirstName() { return firstName; }
}
and the code fragment:
List<Person> prog = Arrays.asList(
new Person("Smith", 1500),
new Person("John", 2000),
new Person("Joe", 1000));
double dVal = prog.stream()
.filter(s -> s.getFirstName().startsWith("J"))
.mapToInt(Person::getSalary)
.average()
.getAsDouble();
System.out.println(dVal);
What is the result?
Options
- A0.0
- B1500.0
- CA compilation error occurs.
- D2000.0
Unlock 1Z0-809 to see the answer
You've previewed enough free 1Z0-809 questions. Unlock 1Z0-809 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.