Method Reference MCQs with answers Page - 7

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 • 833K Points
Coach

Q. What method reference would replace `(e1, e2) -> e1.getName().compareTo(e2.getName())`?

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

A

Admin • 833K Points
Coach

Q. In the real-world, which method reference helps when sorting a list of strings alphabetically?

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

A

Admin • 833K Points
Coach

Q. Which type of method reference is `Employee::getName` when used in mapping operations?

  • (A) Static method reference
  • (B) Instance method of an arbitrary object
  • (C) Instance method of a specific object
  • (D) Constructor reference

A

Admin • 833K Points
Coach

Q. Which functional interface is used with `Supplier<Employee> supplier = Employee::new;`?

  • (A) Supplier
  • (B) Function
  • (C) Consumer
  • (D) Predicate

A

Admin • 833K Points
Coach

Q. What method reference is appropriate for converting a list of numbers to their absolute values using streams?

  • (A) Math::abs
  • (B) Integer::parseInt
  • (C) Number::intValue
  • (D) Collections::max

A

Admin • 833K Points
Coach

Q. Which method reference would replace `str -> str.trim()`?

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

A

Admin • 833K Points
Coach

Q. What is the equivalent method reference for `x -> x.toString()`?

  • (A) Object::toString
  • (B) String::valueOf
  • (C) System.out::print
  • (D) Class::getName

A

Admin • 833K Points
Coach

Q. Which method reference can replace a lambda used in filtering non-empty strings?

  • (A) String::isEmpty
  • (B) String::equals
  • (C) s -> !s.isEmpty()
  • (D) String::isBlank

A

Admin • 833K Points
Coach

Q. What is the correct method reference to print each element in a list?

  • (A) this::print
  • (B) System::println
  • (C) System.out::println
  • (D) Console::log

A

Admin • 833K Points
Coach

Q. Which type of method reference is `System.out::println`?

  • (A) Static method reference
  • (B) Instance method of a specific object
  • (C) Constructor reference
  • (D) Instance method of arbitrary object
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