Lambda expressions can only be used with functional interfaces, which are interfaces with a single abstract method (SAM) but can have any other type of functions:
A. MyInterface4 (Bad syntax dMethod must have default before return type)
B. MyInterface5 (Not valid, has 2 abstract method)
C. MyInterface1 (Valid has one abstract method)
D. MyInterface3 (Not valid, has 2 abstract method)
E. MyInterface2 (Not valid does not have an abstract method)
So, the correct answers are:
C. MyInterface1
If there was a default in option A. MyInterface4 then it will be correct
Correct, only C :
A. MyInterface4=> method abstract cannot contain body
B. MyInterface5 => static method must be a body
C. MyInterface1 => OK
D. MyInterface3=> has two abstract methods NOT SAM
E. MyInterface2=> no abstract methods, booleans equeals is no count as abstract
A. MyInterface4=> method abstract cannot contain body
B. MyInterface5 => OK
C. MyInterface1 => OK
D. MyInterface3=> has two abstract methods NOT SAM
E. MyInterface2=> no abstract methods, booleans equeals is no count as abstract method because is from object class
Lambda expressions can only be used with functional interfaces, which are interfaces with a single abstract method (SAM). Let's analyze the provided interfaces:
A. MyInterface4 (not provided in the initial interfaces)
B. MyInterface5 (valid, as it has a single abstract method)
C. MyInterface1 (not provided in the initial interfaces)
D. MyInterface3 (valid, as it has a single abstract method)
E. MyInterface2 (not valid, as it has more than one abstract method)
So, the correct answers are:
B. MyInterface5
D. MyInterface3
Lambda expressions can only be used with functional interfaces, which are interfaces with a single abstract method (SAM). Let's analyze the provided interfaces:
A. MyInterface4 (not provided in the initial interfaces)
B. MyInterface5 (valid, as it has a single abstract method)
C. MyInterface1 (not provided in the initial interfaces)
D. MyInterface3 (valid, as it has a single abstract method)
E. MyInterface2 (not valid, as it has more than one abstract method)
So, the correct answers are:
B. MyInterface5
D. MyInterface3
MyInterface3 CANNOT BE A FUNCTIONAL INTERFACE. A functional interface can only have 1 abstract method.
Myinterface2 is incorrect because an abstract method cannot be private.
MyInterface4 is incorrect as the compiler will try to insert abstract into the first method which doesn't compile as an abstract method can't have a body.
Myinterface5 won't compile since an abstract method can't be static.
MyInterface1 is the only correct answer as it has exactly 1 abstract method. An interface can contain private methods.
Correct answer: JUST A.
@FunctionalInterface //OK
public interface MyInterface1 {
public int method() throws Exception;
private void pMethod(){}
}
// NO @FunctionalInterface
interface MyInterface2 {
public static void sMethod() {}
private boolean equals(); //is private!! must be abstract| have body
}
// NO @FunctionalInterface - has two abstract methods
interface MyInterface3 {
public void method();
public void method(String str);
}
//@FunctionalInterface: NO
interface MyInterface4 {
public void dMethod() {}//must be static or default: NOT COMPILE
public void Method();
}
To see that an interface is a functional interface, add the annotation @FunctionalInterface. Only functional interfaces can be added to lambda expressions. MyInterface2 and MyInterface4 give compilation error, and MyInterface3 has two abstract methods. So only MyInterface1 is correct, I think...
C. MyInterface1 can be used in a lambda expression because it has exactly one abstract method, method(), which is the requirement for an interface to be a functional interface. A functional interface is an interface that has exactly one abstract method and can be used as the target type for a lambda expression.
D. MyInterface3 can also be used in a lambda expression because it also has exactly one abstract method, method(). The second method, method(String str), is an overloaded version of the first method and does not count as a separate abstract method.
The other options are incorrect because they do not meet the requirement of having exactly one abstract method.
A & D are correct
Because In lambda expression Interface should have only one abstract method.
There should not be any Static method and private method.
So MyInteface3 & MyInterface4 are correct. others are wrong
D Pass -> Interface abstract methods cannot have body
public void method();
public void method(String str);
as well as C
public int method() throws Exception;
private void pMethod() { /* an implementation of pMethod */ }
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
06d854e
4 months agoc47d39c
5 months, 3 weeks agorami_mlaiel
9 months, 1 week agoASPushkin
5 months agoBravo6633
10 months, 2 weeks agod7bb0b2
1 year agod7bb0b2
1 year agod7bb0b2
1 year, 1 month agod7bb0b2
1 year agod7bb0b2
1 year agod7bb0b2
1 year agoKee0369
1 year, 1 month agod7bb0b2
1 year, 1 month agoKee0369
1 year, 1 month ago[Removed]
1 year, 4 months agoOmnisumem
1 year, 5 months agoOmnisumem
1 year, 5 months agoRoxyFoxy
1 year, 7 months agoRoxyFoxy
1 year, 7 months agoStavok
1 year, 7 months agoStavok
1 year, 6 months agoMukes877
1 year, 7 months agoJtic
1 year, 11 months agoRP384
1 year, 11 months agoRP384
1 year, 11 months ago