• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Not understanding the relevant answer

 
Ranch Hand
Posts: 157
jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

As i am practising the enthuware for OCP in JDK 1.8, i have encountered a quuestion which has three options as answers. I have not understood why those three are correct, especially the third option. Please find the code below:



Thanks

Swapna.
 
Saloon Keeper
Posts: 11184
244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which answer do you think, and why?
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this.
Java_Lambda_Method_Reference-.png
[Thumbnail for Java_Lambda_Method_Reference-.png]
Method Reference Lambda
 
Swapna latha
Ranch Hand
Posts: 157
jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1 & 2. But Enthuware has shown that 3rd is also correct answer. Not sure how 3rd is correct answer and even i have doubt why 1 and 2 are also correct.

Stephan van Hulst wrote:Which answer do you think, and why?

 
Bartender
Posts: 2472
108
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isnt it simple to just type the code and check it works ? You can confirm if the answer is correct easily.
can be written as: Hope this helps
 
salvin francis
Bartender
Posts: 2472
108
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd still admit the code is a bit confusing to read at first glance
 
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMO 3rd option is the least confusing

Isn't this how lambda works, if you need an instance of an interface, and the interface is functional i.e. it only has one abstract method, then you can use any method with the same parameters and return type as an implementation of the interface using lambda. In this case the interface has more methods with default implementation, but for any method to be used as an implementation of the interface, you only need to worry about the abstract method in the interface.

To add to Salvin's answer, can you do this:


In the same way do the lambda in all the other options qualify as implementation of Carnivore interface.
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!