Java MCQs with answers Page - 475

Here, you will find a collection of MCQ questions on Java. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

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

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

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

A

Admin • 832.27K 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 • 832.27K 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 • 832.27K 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 • 832.27K 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 • 832.27K 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

A

Admin • 832.27K 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

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ