Method Reference MCQs with answers Page - 6

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. Which is the correct method reference for `String::valueOf`?

  • (A) Converts primitives to Strings
  • (B) Calculates length of String
  • (C) Checks if String is empty
  • (D) Returns a substring

A

Admin • 833K Points
Coach

Q. What kind of reference is `Arrays::sort`?

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

A

Admin • 833K Points
Coach

Q. Which method reference form would match `Function<String, Integer> length = String::length;`?

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

A

Admin • 833K Points
Coach

Q. Is `object::staticMethod` a valid method reference?

  • (A) Yes
  • (B) No
  • (C) Only if the method is overloaded
  • (D) Only if the method is private

A

Admin • 833K Points
Coach

Q. What is returned by `Function<String, String> f = String::trim;` when applied to " Hello "?

  • (A) Hello
  • (B) Hello
  • (C) hello
  • (D) HELLO

A

Admin • 833K Points
Coach

Q. Which interface is typically used with `ClassName::new` to provide objects?

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

A

Admin • 833K Points
Coach

Q. In which Java version were method references introduced?

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

A

Admin • 833K Points
Coach

Q. Can method references refer to overloaded methods?

  • (A) Yes, if the context determines the correct method
  • (B) No, overloading is not supported
  • (C) Only if methods differ in return type
  • (D) Only for static methods

A

Admin • 833K Points
Coach

Q. Which method reference is commonly used to print each element of a collection?

  • (A) Class::print
  • (B) System.out::print
  • (C) System.out::println
  • (D) System::out

A

Admin • 833K Points
Coach

Q. Which method reference is used to create new objects via Supplier?

  • (A) ClassName::methodName
  • (B) ClassName::new
  • (C) ClassName.new()
  • (D) objectName::new
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