πŸ“Š JAVA
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
πŸ’¬ Discuss
βœ… Correct Answer: (C) System.out::println

Explanation: System.out::println is used to print each element.

πŸ“Š JAVA
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
πŸ’¬ Discuss
βœ… Correct Answer: (B) Instance method of a specific object

Explanation: It is an instance method of the specific object System.out.

πŸ“Š JAVA
Q. What method reference could map Employee objects to their ages?
  • (A) Employee::getName
  • (B) Employee::getAge
  • (C) Employee::compareTo
  • (D) Employee::new
πŸ’¬ Discuss
βœ… Correct Answer: (B) Employee::getAge

Explanation: `Employee::getAge` retrieves the age property.

πŸ“Š JAVA
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>
πŸ’¬ Discuss
βœ… Correct Answer: (A) Function<String, Integer>

Explanation: `Function<String, Integer>` matches input String and returns Integer length.

πŸ“Š JAVA
Q. Which method reference helps to instantiate a new ArrayList?
  • (A) ArrayList::size
  • (B) ArrayList::add
  • (C) ArrayList::new
  • (D) Collections::emptyList
πŸ’¬ Discuss
βœ… Correct Answer: (C) ArrayList::new

Explanation: `ArrayList::new` is a constructor reference.

πŸ“Š JAVA
Q. Which method reference is ideal for sorting a list of integers?
  • (A) Math::max
  • (B) Integer::compareTo
  • (C) Integer::sum
  • (D) Integer::parseInt
πŸ’¬ Discuss
βœ… Correct Answer: (B) Integer::compareTo

Explanation: `Integer::compareTo` can be used to compare integers.

πŸ“Š JAVA
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
πŸ’¬ Discuss
βœ… Correct Answer: (B) String::compareToIgnoreCase

Explanation: `String::compareToIgnoreCase` compares two strings ignoring case.

πŸ“Š JAVA
Q. What method reference would replace `() -> new Employee()`?
  • (A) Employee::getName
  • (B) Employee::new
  • (C) Employee::toString
  • (D) Employee::compareTo
πŸ’¬ Discuss
βœ… Correct Answer: (B) Employee::new

Explanation: `Employee::new` is the constructor reference replacing the no-arg lambda.

πŸ“Š JAVA
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
πŸ’¬ Discuss
βœ… Correct Answer: (B) String::toUpperCase

Explanation: `String::toUpperCase` maps strings to uppercase.

πŸ“Š JAVA
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
πŸ’¬ Discuss
βœ… Correct Answer: (A) String::length

Explanation: `String::length` returns the length of each string.