• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sybex Practice Tests 11, chapter 3, page 73

 
Ranch Hand
Posts: 74
2
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Why aren't answer B and F the right answers? The Panther interface and Cub could be:



And this compiles and I have two abstract methods in Panther. The Answer E only says:

"If Panther has two abstract methods, Cub may be a functional interface."

And that is true. The answer says nothing about methods from Object?! I now that the methods from Object doesn't count to be a functional interface but in Panther there are definitely two abstract methods and in the above mentioned case,
Cub can be a functional interface. And therefore E should be right not F.

Thanks for explanation.

Michael

 
Bartender
Posts: 1737
63
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you provide some more context for this question so that those who don't have the exact book can help to answer it?

I own the two-book version and was having some trouble finding the part of my text that corresponds to the CSG.

The authors will eventually see this, but like finalize() and resource management it might be better to not have to wait for them or someone else that has the exact version to come along.

The contents of the two book version are essentially the same as the CSG, but it is sometimes difficult to find the right pages.

Also, people who don't own the books may wish to help answer.
For that purpose you can provide more context from something you think may be wrong.

Don't post content from the Sybex Books in random places on the web.
Don't post extensive content from random copyrighted material here.

However, in this forum, it is permitted by the publisher to post enough context about questions about possible errata in the books to allow the forum as a whole to productively answer you.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Gualeni wrote:The answer says nothing about methods from Object?! I now that the methods from Object doesn't count to be a functional interface but in Panther there are definitely two abstract methods...



I don't know what any of the answers in the book are. But you're right, methods in Object "don't count" as methods of an interface for the purpose of determining whether it can be a functional interface. And explicitly declaring them in the interface doesn't change that. So effectively the toString() method "doesn't count".
 
Mike Gualeni
Ranch Hand
Posts: 74
2
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer in the book was only:

Suppose Panther and Cub are interfaces and neither contains any default methods. Which statements are true? (Choose two.)

And a picture that indicates that Cub extends Panther

And the answers are:

A. If Panther has a single abstract method, Cub is guaranteed to be a functional interface.

B. If Panther has a single abstract method, Cub may be a functional interface.

C. If Panther has a single abstract method, Cub cannot be a functional interface.

D. If Panther has two abstract methods, Cub is guaranteed to be a functional interface.

E. If Panther has two abstract methods, Cub may be a functional interface.

F. If Panther has two abstract methods, Cub cannot be a functional interface.


And in the book the right answers are B and F. But when I look the question and the answer without mentioning that the methods from Object doesn't count, E could also be right as I sad in my first post. I know a functional interface has only one abstract method (SAM). But when i put String toString(); in the Panther interface it has two abstract methods and it is still a functional interface so E could be right.


 
Jesse Silverman
Bartender
Posts: 1737
63
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still to this moment don't understand why Java allows you to redeclare abstract methods inherited from Object in your interfaces -- I don't see what this really ever buys you except confusion.

I guess that someone decided that was allowed and legal far, long, way before there was any notion of Java 8's functional interface, they decided to let you do this for some reason, and we don't break compatibility without the utmost of necessity.  We kill ourselves before introducing new keywords, etc. too.

[Actually, straining my brain, I guess it could be to suggest that the implementing class should not be content with inheriting Object's implementation, but that they should be overriding it in an appropriate manner?]

From what I can tell here:
https://docs.oracle.com/javase/specs/jls/se11/html/jls-4.html#jls-4.3.2

There are eight, or nine or ten (I used to have it memorized, didn't have the energy to even count them right now) abstract methods belonging to Object that may optionally be re-declared in any Interface, none of which would count towards the total of exactly One that is required to be a legal @FunctionalInterface.

I think that the question is just trying to ensure we are aware of these rules, but I find it even more confusing the way it is worded.

I would protest this question, but most of the fault lies with Java's existing ability to re-declare Object methods.

Many free preparatory materials don't even go into the odd fact that interfaces can re-declare Object methods that don't count towards the "total of one".

While it is fair to write a question that would cause someone who used these materials to prepare for the exam to get the wrong answer, this feels more like the literacy tests that used to be used to disenfranchise voters.  I know more than I'd ever want to about the requirements for @FunctionalInterface and still have reservations about what answers they are looking for.

Working backwards from the answers,
B, not A because if the single abstract method happens to be a re-declaration of one from Object, then A itself isn't a functional interface.  Also, even if A isn't for that reason, maybe B declares one real, new single abstract method...

C certainly isn't true in two ways, either Cub declares no NEW non-inherited abstract methods, and Panther had one, or B declares one and Panther had none (tho then A wasn't a @FunctionalInterface)...

At least D is obviously wrong, if both methods were just re-declarations of Object methods, then Cub would need one to be a valid @FunctionalInterface, if NEITHER were, then it is absolutely hopeless, but they don't say that.

E seems more right to me than F, if the question isn't stating that A inherits one from Object and declares one new one.

It is not the fault of the mock question authors nor the exam authors (presumably) that Interfaces can (pointlessly?) re-declare abstract methods inherited from Object.  Since that can happen, it is proper to require knowing that this can happen and that this doesn't count towards the total of One that is necessary.

I'd go further and agree that one needs to know that neither default methods, private methods nor static methods, public or private count towards that total of one.  They can certainly be there or not, and do not conflict with the requirements.

Any questions about validity of candidates for @FunctionalInterface should be easily answered by someone that knows these rules.  From the part of the question that made it into this thread, this would be a questionable question.

I failed to find this in my Sybex 816 book -- so I haven't looked directly at the question, but from what I saw in this thread, I'd have been confused and stressed by the question and answers, and I think I could teach a mini-lesson on this correctly.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesse Silverman wrote:I still to this moment don't understand why Java allows you to redeclare abstract methods inherited from Object in your interfaces -- I don't see what this really ever buys you except confusion.



It does save you from having to write a rule to say that's not allowed, I suppose. And another compiler error message. And as for confusion, where would the certification exams be without it?
 
Jesse Silverman
Bartender
Posts: 1737
63
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They can test (in Java 11) to make sure you know that default and static methods in the interface don't count towards the total!

That is important, useful and fair.

This question has a serious "Simon Says!!" feel to it due to the inherited Object methods ambiguities.

Maybe showing them quite explicitly and having you recognize that they came from Object so they don't count might be fair play, going beyond that just dives into murk and mire.

This is an example of why I get so OCD about minor details when I am studying Java with an intent towards certification.

Some people are like "Dude, that is a tiny minor detail, relax!"

But many of those tiny minor details seem more major than other points that can easily cause you to blow a question or five.
 
Mike Gualeni
Ranch Hand
Posts: 74
2
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your answers.

And I'm sorry, the subject is not "Sybex CSG 11", it should be:

             "Sybex Practice Tests 11"

That's why your failed to find it.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I edited the subject to say practice tests. Hmm. That would start a debate about whether those methods are abstract since they are implemented. (Vs being redundant in the interface.) I see your point though and make a note on our "things that are unclear" list.
reply
    Bookmark Topic Watch Topic
  • New Topic