πŸ“Š JAVA
Q. Which is a valid method reference for creating a new `ArrayList`?
  • (A) ArrayList::add
  • (B) ArrayList::new
  • (C) ArrayList::size
  • (D) ArrayList::get
πŸ’¬ Discuss
βœ… Correct Answer: (B) ArrayList::new

Explanation: `ArrayList::new` is a constructor reference to create a new `ArrayList` instance.

πŸ“Š JAVA
Q. In which scenario can method references replace a lambda?
  • (A) When the lambda body contains multiple statements
  • (B) When lambda only invokes a method
  • (C) When lambda throws exceptions
  • (D) When lambda accesses outer variables
πŸ’¬ Discuss
βœ… Correct Answer: (B) When lambda only invokes a method

Explanation: Method references can replace lambdas that invoke a method directly.

πŸ“Š JAVA
Q. Which is the correct method reference for `String::valueOf`?
  • (A) Converts primitives to Strings
  • (B) Calculates length of String
  • (C) Checks if String is empty
  • (D) Returns a substring
πŸ’¬ Discuss
βœ… Correct Answer: (A) Converts primitives to Strings

Explanation: `String::valueOf` converts primitives and objects to their string representation.

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

Explanation: `Arrays::sort` refers to a static method.

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

Explanation: `String::length` is an instance method of an arbitrary `String` object.

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

Explanation: Static methods must be referenced by class name, not object name.

πŸ“Š JAVA
Q. What is returned by `Function<String, String> f = String::trim;` when applied to " Hello "?
  • (A) Hello
  • (B) Hello
  • (C) hello
  • (D) HELLO
πŸ’¬ Discuss
βœ… Correct Answer: (A) Hello

Explanation: String::trim removes leading and trailing spaces.

πŸ“Š JAVA
Q. Which interface is typically used with `ClassName::new` to provide objects?
  • (A) Supplier
  • (B) Consumer
  • (C) Predicate
  • (D) Function
πŸ’¬ Discuss
βœ… Correct Answer: (A) Supplier

Explanation: Supplier provides instances via a no-arg constructor.

πŸ“Š JAVA
Q. In which Java version were method references introduced?
  • (A) Java 7
  • (B) Java 8
  • (C) Java 9
  • (D) Java 10
πŸ’¬ Discuss
βœ… Correct Answer: (B) Java 8

Explanation: Method references are a feature of Java 8.

πŸ“Š JAVA
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
πŸ’¬ Discuss
βœ… Correct Answer: (A) Yes, if the context determines the correct method

Explanation: Overloaded methods can be referenced if the functional interface signature resolves to the correct method.