Method Reference MCQs with answers Page - 2

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. Method references can be used in combination with which Java feature?

  • (A) Generics
  • (B) Streams API
  • (C) Reflection
  • (D) Serialization

A

Admin • 802.91K Points
Coach

Q. What is the equivalent method reference for `(x, y) -> Integer.compare(x, y)`?

  • (A) Integer::parseInt
  • (B) Integer::compare
  • (C) Math::max
  • (D) Integer::valueOf

A

Admin • 802.91K Points
Coach

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

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

A

Admin • 802.91K Points
Coach

Q. What kind of method reference is `Thread::new`?

  • (A) Static method reference
  • (B) Instance method reference
  • (C) Constructor reference
  • (D) Field reference

A

Admin • 802.91K Points
Coach

Q. Can method references replace lambda expressions?

  • (A) No
  • (B) Yes, when the lambda body is just a method call
  • (C) Only for static methods
  • (D) Only in Java 9 and above

A

Admin • 802.91K Points
Coach

Q. What is the method reference equivalent of `() -> ClassName.staticMethod()`?

  • (A) ClassName::instanceMethod
  • (B) ClassName::staticMethod
  • (C) new ClassName()::staticMethod
  • (D) this::staticMethod

A

Admin • 802.91K Points
Coach

Q. Which interface is often used with a constructor reference like `ArrayList::new`?

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

A

Admin • 802.91K Points
Coach

Q. What kind of method reference is used in `objectName::methodName`?

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

A

Admin • 802.91K Points
Coach

Q. Method references are part of which Java version?

  • (A) Java 6
  • (B) Java 7
  • (C) Java 8
  • (D) Java 9

A

Admin • 802.91K Points
Coach

Q. Can a method reference refer to a method with parameters?

  • (A) No
  • (B) Yes, if compatible with the functional interface
  • (C) Only static methods
  • (D) Only constructors
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