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

Given:

What is the result?

    Correct Answer: B

    In the provided Java code, the `Job` constructor initializes the `cost` variable with `null`. The `getCost` method is defined to return an `int`, which is a primitive type and cannot be `null`. When the `getCost` method is invoked on the `Job` object, the attempt to unbox the `null` value into an `int` will cause a `NullPointerException` at runtime. Therefore, the result is that a `NullPointerException` is thrown.

Discussion
pul26Option: B

Answer is B

WilsonKKerllOption: B

NullPointerExcepiton

ChirajOption: B

The answer is B tested.

asdfjhfgjuaDCVOption: B

B is the answer

steefaandOption: B

Answer is B, tested, NPE happens since Supplier provides null.

Tarik2190Option: B

Answer is B, class Job { String name; Integer cost; Job(String name, Integer cost) { this.name = name; this.cost = cost; } public String getName() { return name; } public int getCost() { return cost; } } public class Test { public static void main (String[] args) throws InterruptedException, ExecutionException { Job j1 = new Job("IT", null); DoubleSupplier dS = j1::getCost; System.out.println(j1.getName() + ": " + dS.getAsDouble()); } }

Svetleto13Option: B

B,tested.If we replace Integer(object) with int(primitive) answer is D.

JME_CHG

When I change int getCost() to Integer getCost() I thought DoubleSupplier line would fail compilation but it continued to work, anyone know why?

hmcbq

I think that int can't be null because it is primitive. But Integer is an object.

Syyyyyyyy

DoubleSupplier returns primitive double instead of Object Double, so since Integer can be cast to double, code will compile.