Java MCQs with answers Page - 478

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

Q. What functional interface would you use with `String::length` in a stream mapping?

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

A

Admin • 831.35K Points
Coach

Q. Which method reference helps to instantiate a new ArrayList?

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

A

Admin • 831.35K Points
Coach

Q. Which method reference is ideal for sorting a list of integers?

  • (A) Math::max
  • (B) Integer::compareTo
  • (C) Integer::sum
  • (D) Integer::parseInt

A

Admin • 831.35K Points
Coach

Q. Which is the method reference equivalent of `(a, b) -> a.compareToIgnoreCase(b)`?

  • (A) String::compareTo
  • (B) String::compareToIgnoreCase
  • (C) String::toLowerCase
  • (D) String::isEmpty

A

Admin • 831.35K Points
Coach

Q. What method reference would replace `() -> new Employee()`?

  • (A) Employee::getName
  • (B) Employee::new
  • (C) Employee::toString
  • (D) Employee::compareTo

A

Admin • 831.35K Points
Coach

Q. To map a stream of strings to their uppercase form, which method reference is used?

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

A

Admin • 831.35K Points
Coach

Q. Which method reference would map a collection of strings to their lengths?

  • (A) String::length
  • (B) String::valueOf
  • (C) String::charAt
  • (D) String::substring

A

Admin • 831.35K Points
Coach

Q. What is a functional interface in Java?

  • (A) An interface with default methods only
  • (B) An interface with exactly one abstract method
  • (C) Any interface with static methods
  • (D) Any abstract class

A

Admin • 831.35K Points
Coach

Q. Which annotation is used to indicate a functional interface?

  • (A) @Override
  • (B) @FunctionalInterface
  • (C) @Deprecated
  • (D) @Interface

A

Admin • 831.35K Points
Coach

Q. Which of the following is a functional interface?

  • (A) Runnable
  • (B) Serializable
  • (C) Comparable
  • (D) Cloneable

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