1z0-809 Exam QuestionsBrowse all questions from this exam

1z0-809 Exam - Question 92


Given:

What is the result?

Show Answer
Correct Answer: BD

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

8 comments
Sign in to comment
pul26Option: B
Dec 8, 2020

Answer is B

ChirajOption: B
Feb 15, 2021

The answer is B tested.

WilsonKKerllOption: B
Mar 14, 2022

NullPointerExcepiton

JME_CHG
Apr 10, 2021

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

hmcbq
Apr 18, 2021

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

Syyyyyyyy
Jun 3, 2024

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

Svetleto13Option: B
May 13, 2021

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

Tarik2190Option: B
May 17, 2021

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()); } }

steefaandOption: B
Feb 6, 2024

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

asdfjhfgjuaDCVOption: B
Mar 7, 2024

B is the answer