Java MCQs with answers Page - 477

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

Q. In the real-world, which method reference helps when sorting a list of strings alphabetically?

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

A

Admin • 833.24K Points
Coach

Q. Which type of method reference is `Employee::getName` when used in mapping operations?

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

A

Admin • 833.24K Points
Coach

Q. Which functional interface is used with `Supplier<Employee> supplier = Employee::new;`?

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

A

Admin • 833.24K Points
Coach

Q. What method reference is appropriate for converting a list of numbers to their absolute values using streams?

  • (A) Math::abs
  • (B) Integer::parseInt
  • (C) Number::intValue
  • (D) Collections::max

A

Admin • 833.24K Points
Coach

Q. Which method reference would replace `str -> str.trim()`?

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

A

Admin • 833.24K Points
Coach

Q. What is the equivalent method reference for `x -> x.toString()`?

  • (A) Object::toString
  • (B) String::valueOf
  • (C) System.out::print
  • (D) Class::getName

A

Admin • 833.24K Points
Coach

Q. Which method reference can replace a lambda used in filtering non-empty strings?

  • (A) String::isEmpty
  • (B) String::equals
  • (C) s -> !s.isEmpty()
  • (D) String::isBlank

A

Admin • 833.24K Points
Coach

Q. What is the correct method reference to print each element in a list?

  • (A) this::print
  • (B) System::println
  • (C) System.out::println
  • (D) Console::log

A

Admin • 833.24K Points
Coach

Q. Which type of method reference is `System.out::println`?

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

A

Admin • 833.24K Points
Coach

Q. What method reference could map Employee objects to their ages?

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

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