Method Reference MCQs with answers Page - 3

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 form of method reference is used to refer to an instance method of an existing object?

  • (A) ClassName::methodName
  • (B) object::methodName
  • (C) ClassName::new
  • (D) ClassName::staticMethod

A

Admin • 828.43K Points
Coach

Q. Which functional interface is most suitable for `System.out::println`?

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

A

Admin • 828.43K Points
Coach

Q. Which form of method reference is `ClassName::staticMethodName`?

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

A

Admin • 828.43K Points
Coach

Q. Which is a valid method reference to a constructor?

  • (A) ClassName::methodName
  • (B) ClassName::new
  • (C) new::ClassName
  • (D) ClassName::create

A

Admin • 828.43K Points
Coach

Q. Which method reference is equivalent to `str -> str.trim()`?

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

A

Admin • 828.43K Points
Coach

Q. What is the output of `Arrays.asList("a", "b").forEach(System.out::println);`?

  • (A) No output
  • (B) Prints 'a' and 'b' on separate lines
  • (C) Prints 'ab'
  • (D) Compilation error

A

Admin • 828.43K Points
Coach

Q. Method references can replace lambdas when:

  • (A) Lambda only calls a method
  • (B) Lambda has multiple statements
  • (C) Lambda throws an exception
  • (D) Lambda modifies external variables

A

Admin • 828.43K Points
Coach

Q. Which is the correct way to reference an instance method on an arbitrary object?

  • (A) object::method
  • (B) ClassName::method
  • (C) ClassName::new
  • (D) this::method

A

Admin • 828.43K Points
Coach

Q. Which method reference type allows creating new object instances?

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

A

Admin • 828.43K Points
Coach

Q. What does `Function<String, Integer> lengthFunc = String::length;` do?

  • (A) Creates a string
  • (B) Maps string to its length
  • (C) Converts integer to string
  • (D) Checks if string is empty
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