Method Reference MCQs with answers Page - 8

You will find multiple-choice questions (MCQs) related to #Method Reference here. Go through these questions to prepare effectively for your upcoming exams and interviews.

To view the correct answer for any question, simply click the "Show Answer" button.

Have a question to share? Click on "Add Question" to contribute!

A

Admin • 802.91K Points
Coach

Q. What method reference could map Employee objects to their ages?

  • (A) Employee::getName
  • (B) Employee::getAge
  • (C) Employee::compareTo
  • (D) Employee::new

A

Admin • 802.91K Points
Coach

Q. What functional interface would you use with `String::length` in a stream mapping?

  • (A) Function<String, Integer>
  • (B) Predicate<String>
  • (C) Supplier<Integer>
  • (D) Consumer<String>

A

Admin • 802.91K Points
Coach

Q. Which method reference helps to instantiate a new ArrayList?

  • (A) ArrayList::size
  • (B) ArrayList::add
  • (C) ArrayList::new
  • (D) Collections::emptyList

A

Admin • 802.91K Points
Coach

Q. Which method reference is ideal for sorting a list of integers?

  • (A) Math::max
  • (B) Integer::compareTo
  • (C) Integer::sum
  • (D) Integer::parseInt

A

Admin • 802.91K Points
Coach

Q. Which is the method reference equivalent of `(a, b) -> a.compareToIgnoreCase(b)`?

  • (A) String::compareTo
  • (B) String::compareToIgnoreCase
  • (C) String::toLowerCase
  • (D) String::isEmpty

A

Admin • 802.91K Points
Coach

Q. What method reference would replace `() -> new Employee()`?

  • (A) Employee::getName
  • (B) Employee::new
  • (C) Employee::toString
  • (D) Employee::compareTo

A

Admin • 802.91K Points
Coach

Q. To map a stream of strings to their uppercase form, which method reference is used?

  • (A) String::toLowerCase
  • (B) String::toUpperCase
  • (C) String::trim
  • (D) String::substring

A

Admin • 802.91K Points
Coach

Q. Which method reference would map a collection of strings to their lengths?

  • (A) String::length
  • (B) String::valueOf
  • (C) String::charAt
  • (D) String::substring
What's Tag

As you may know, questions are organized under broad categories. Each category can include various types of questions. For example, the "History" category might contain questions about the Revolt of 1857, Shivaji Maharaj, Ancient History, Buddhism, and more.

To further refine this organization, we've introduced tags, which act as sub-categories to group questions more specifically.

Verified users can add tags to any question. If you have any suggestions regarding this system, we'd love to hear from you. Contact Us

Learn More