Method References

1.What is a method reference in Java?
  • A. A way to call a method using its full class name.
  • B. A shorthand for a lambda expression that simply calls an existing method.
  • C. A reference to a static variable.
  • D. A mechanism for direct memory access.

A shorthand for a lambda expression that simply calls an existing method.

A shorthand for a lambda expression that simply calls an existing method.

2.Which of the following is the syntax for a static method reference?
  • A. ClassName::methodName
  • B. object::methodName
  • C. ClassName.super::methodName
  • D. new ClassName::methodName

ClassName::methodName

ClassName::methodName

3.When can a method reference be used?
  • A. Anywhere a regular method call is made.
  • B. Only within try-catch blocks.
  • C. Where a functional interface is expected as an argument.
  • D. To replace constructors entirely.

Where a functional interface is expected as an argument.

Where a functional interface is expected as an argument.

4.Which type of method reference is String::length?
  • A. Static method reference
  • B. Instance method reference of a particular object
  • C. Instance method reference of an arbitrary object of a particular type
  • D. Constructor reference

Instance method reference of an arbitrary object of a particular type

Instance method reference of an arbitrary object of a particular type

5.What is the main benefit of using method references?
  • A. They make code more verbose and less readable.
  • B. They allow for more efficient memory allocation.
  • C. They provide a more concise and readable way to represent simple lambda expressions.
  • D. They enable direct manipulation of object memory.

They provide a more concise and readable way to represent simple lambda expressions.

They provide a more concise and readable way to represent simple lambda expressions.