Method Reference MCQs with answers Page - 5

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

Q. Which of these is NOT a valid form of method reference?

  • (A) ClassName::staticMethodName
  • (B) ClassName::instanceMethodName
  • (C) objectName::instanceMethodName
  • (D) ClassName::fieldName

A

Admin • 828.43K Points
Coach

Q. Given `Comparator<String> comp = String::compareToIgnoreCase;`, what does the method reference resolve to?

  • (A) Comparator comparing case-sensitive strings
  • (B) Comparator comparing case-insensitive strings
  • (C) Sorting strings by length
  • (D) It won't compile

A

Admin • 828.43K Points
Coach

Q. What type of method reference is `this::equals`?

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

A

Admin • 828.43K Points
Coach

Q. Which functional interface matches with `String::new` when used with a Supplier?

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

A

Admin • 828.43K Points
Coach

Q. Which method reference replaces `s -> s.isEmpty()`?

  • (A) String::isEmpty
  • (B) String::length
  • (C) String::substring
  • (D) String::equals

A

Admin • 828.43K Points
Coach

Q. Which method reference is equivalent to `(list, e) -> list.add(e)`?

  • (A) List::size
  • (B) List::add
  • (C) Collections::sort
  • (D) List::get

A

Admin • 828.43K Points
Coach

Q. Method references require the functional interface to match in:

  • (A) Return type only
  • (B) Parameter list and return type
  • (C) Parameter names only
  • (D) Return type only, parameters optional

A

Admin • 828.43K Points
Coach

Q. What does `super::methodName` refer to?

  • (A) Superclass method
  • (B) Static method
  • (C) Instance method of the same class
  • (D) Constructor of the superclass

A

Admin • 828.43K Points
Coach

Q. Which is a valid method reference for creating a new `ArrayList`?

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

A

Admin • 828.43K Points
Coach

Q. In which scenario can method references replace a lambda?

  • (A) When the lambda body contains multiple statements
  • (B) When lambda only invokes a method
  • (C) When lambda throws exceptions
  • (D) When lambda accesses outer variables
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