Java OCA OCP Practice Question 1667

Question

Which of the following method references can be passed to a method that takes Consumer<Object> as an argument?

  • I. ArrayList::new
  • II. String::new
  • III. System.out::println
  • A. I only
  • B. I, II, and III
  • C. I and III
  • D. III only


D.

Note

First of all, Consumer<Object> takes a single Object argument and does not return any data.

The classes ArrayList and String do not contain constructors that take an Object, so neither of the first two statements are correct.

The third statement does support an Object variable, since the System.out.println(Object) method exists.

Option D is the correct answer.




PreviousNext

Related