The correct option to create a method reference to the static method 'borrowBook' in the 'Student' class is B. BiConsumer transaction = Student::borrowBook, since it can take one parameter and return void. Other options do not match the method's signature or return type.
;
In this question, we're discussing method references in Java, a feature introduced in Java 8. The concept revolves around using a shorthand syntax to express a lambda expression that delegates an action to a static method.
Possible Function Interfaces:
BiFunction: This interface represents a function that accepts two arguments and produces a result.
BiConsumer: This interface represents an operation that accepts two arguments and returns no result.
Consumer: This interface represents an operation that accepts a single argument and returns no result.
Predicate: This interface represents a boolean-valued function that takes one argument.
Analysis:
The method borrowBook in class Student is a static method that accepts a single argument of type Integer and returns void (it prints a message). The best functional interface matching this signature is Consumer , which takes one argument and does not return any value.
Conclusion:
Based on the method's signature and the characteristics of the provided functional interfaces, the correct option to create a method reference to the static method borrowBook is:
Consumer transaction = Student::borrowBook;