Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 30

Given the code fragments:

class Employee {

Optional

address;

Employee (Optional

address) {

this.address = address;

}

public Optional

getAddress() { return address; }

}

class Address {

String city = "New York";

public String getCity { return city: }

public String toString() {

return city;

}

}

and

Address address = null;

Optional

addrs1 = Optional.ofNullable (address);

Employee e1 = new Employee (addrs1);

String eAddress = (addrs1.isPresent()) ? addrs1.get().getCity() : "City Not available";

What is the result?

    Correct Answer: B

    The code creates an Optional<Address> and initializes it with a null value using Optional.ofNullable(address). This means the Optional does not contain a value. Therefore, when checking if addrs1.isPresent(), the condition is false, resulting in the expression evaluating to 'City Not available'.

Discussion
adnano1234Option: B

The correct answer is B

asdfjhfgjuaDCVOption: B

The correct answer is B.

steefaandOption: B

B is correct since address is not present.

r1muka5Option: B

Answer is B.

DestroyerOption: B

Answer is B