Java MCQs with answers Page - 476

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.01K 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 • 832.01K 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 • 832.01K 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 • 832.01K 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 • 832.01K Points
Coach

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

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

A

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

A

Admin • 832.01K Points
Coach

Q. What method reference would replace `(e1, e2) -> e1.getName().compareTo(e2.getName())`?

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

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