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

Explanation: `System.out::println` prints each element when used in forEach or streams.

πŸ“Š JAVA
Q. Which method reference is used to create new objects via Supplier?
  • (A) ClassName::methodName
  • (B) ClassName::new
  • (C) ClassName.new()
  • (D) objectName::new
πŸ’¬ Discuss
βœ… Correct Answer: (B) ClassName::new

Explanation: `ClassName::new` is a constructor reference used with Supplier.

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

Explanation: If `compareByName` is a static method, it can be used as `Employee::compareByName`.

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

Explanation: `String::compareTo` is used for natural ordering of strings.

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

Explanation: `Employee::getName` refers to an instance method of arbitrary objects of Employee.

πŸ“Š JAVA
Q. Which functional interface is used with `Supplier<Employee> supplier = Employee::new;`?
  • (A) Supplier
  • (B) Function
  • (C) Consumer
  • (D) Predicate
πŸ’¬ Discuss
βœ… Correct Answer: (A) Supplier

Explanation: Supplier represents a no-argument constructor reference.

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

Explanation: `Math::abs` converts numbers to their absolute values.

πŸ“Š JAVA
Q. Which method reference would replace `str -> str.trim()`?
  • (A) String::toUpperCase
  • (B) String::trim
  • (C) String::substring
  • (D) String::isEmpty
πŸ’¬ Discuss
βœ… Correct Answer: (B) String::trim

Explanation: `String::trim` is used to remove leading and trailing spaces.

πŸ“Š JAVA
Q. What is the equivalent method reference for `x -> x.toString()`?
  • (A) Object::toString
  • (B) String::valueOf
  • (C) System.out::print
  • (D) Class::getName
πŸ’¬ Discuss
βœ… Correct Answer: (A) Object::toString

Explanation: `Object::toString` returns the string representation of an object.

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

Explanation: However, there is no direct method reference for negation; still, this lambda form is often used.