Which of the following correctly uses method reference with constructor?
AString::new
Bnew String::
CString->new
Dnew::String
Correct Answer:
A. String::new
EXPLANATION
Constructor method references use ClassName::new syntax. String::new refers to the String constructor and can be used wherever a Supplier<String> is expected.
In the lambda expression (a, b) -> a.compareTo(b), what can we infer about the parameters?
ABoth a and b are integers
BBoth a and b are Comparable objects
Ca is a String and b is a number
DTypes cannot be determined without context
Correct Answer:
D. Types cannot be determined without context
EXPLANATION
Without explicit type declarations or context, the compiler must infer types from usage. We can only determine they have a compareTo() method, likely Comparable types.
What issue can arise when using lambda expressions with checked exceptions?
AChecked exceptions cannot be thrown directly in lambda expressions
BThey must be wrapped in try-catch or a custom functional interface must be created
CChecked exceptions automatically become unchecked in lambdas
DLambda expressions cannot handle any exceptions
Correct Answer:
B. They must be wrapped in try-catch or a custom functional interface must be created
EXPLANATION
Since standard functional interfaces don't declare checked exceptions, you must either wrap in try-catch or create a custom functional interface that throws the checked exception.