exam questions

Exam 1z0-819 All Questions

View all questions & answers for the 1z0-819 exam

Exam 1z0-819 topic 1 question 41 discussion

Actual exam question from Oracle's 1z0-819
Question #: 41
Topic #: 1
[All 1z0-819 Questions]

Given the code fragment:
public void foo(Function<Integer, String> fun) {...}
Which two compile? (Choose two.)

  • A. foo( n -> Integer.toHexString(n) )
  • B. foo( toHexString )
  • C. foo( n -> n + 1 )
  • D. foo( int n -> Integer.toHexString(n) )
  • E. foo( n -> Integer::toHexString )
  • F. foo( Integer::toHexString )
  • G. foo( n::toHexString )
  • H. foo( (int n) -> Integer.toHexString(n) )
Show Suggested Answer Hide Answer
Suggested Answer: AF 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
ASPushkin
1 week, 2 days ago
Selected Answer: AF
Case (h) is of interest for such option as the incompatible parameter types in lambda expression with its functional interface. Types must match.
upvoted 1 times
...
Omnisumem
5 months ago
Selected Answer: AF
Tested: A and F.
upvoted 1 times
...
Stavok
6 months ago
Selected Answer: AF
A. foo( n -> Integer.toHexString(n) ) is a correct answer because it uses a lambda expression to define the implementation of the Function interface. The lambda expression takes an Integer as input and returns a String as output, which matches the expected input and output types of the Function interface. F. foo( Integer::toHexString ) is also a correct answer because it uses a method reference to define the implementation of the Function interface. The method reference refers to the toHexString method of the Integer class, which takes an Integer as input and returns a String as output, matching the expected input and output types of the Function interface.
upvoted 3 times
...
tmuralimanohar
6 months, 2 weeks ago
Answer: AF
upvoted 1 times
...
Mukes877
7 months, 2 weeks ago
Selected Answer: AF
A & F are correct because in (int n ) -> Integer.hexString(n) -- there is no need of parameterType because it is already declared in further function.
upvoted 1 times
...
Obalt
11 months, 2 weeks ago
Correct answer is A & F
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago