Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

OCP Java SE 11 Programmer I Study Guide (Sybex) Possible Errata Bonus Test 2 Overriding/Overridden

 
Jesse Silverman
Saloon Keeper
Posts: 1343
40
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
While I got this question marked correct, the checked exceptions my brain threw while executing it helped me just miss the 90 minute cut-off I'd set for myself doing the first 50 problems.
I would play "Let It Go" on headphones while taking the exam, but in real conditions that would be an auto-fail.  No headphones, no music, and NO MUMBLING/READING ALOUD.  Yikes!

I consulted the JLS before posting this, and first, let me say that there is a LOT that the JLS has to say about inheritance, implementation of interfaces and overriding that you hardly see anywhere else, and it can matter.  My mind got blown by how much there is in there that is probably worth reading a few times to take my knowledge of the subject to the Next Level in various subtle ways and edge cases, BUT...

I believe when we have a Super-type (Interface or Abstract or Concrete Class) that is then implemented/extended by a sub-interface, implementing class or sub-class, the JLS (like myself) consistently refers to the abstract or concrete method contained in the super-class as the overridden method, and consistently refers to the sub-class or sub-interface or implementing class method as the overriding method.  In JLS 17 there are 73 references to overriding and 51 to the term overridden, which all seem to be used with the same polarity.

To further complicate things, in a complex inheritance hierarchy, the same exact method can itself be both overriding and in turn, overridden in a further sub-class, but that situation is not described or involved in the question.

So while reading this I kept thinking about horses riding cowboys and such.  I think it is clear what the answers mean to say, but they are misusing the terminology.

Question 46 tb584704.JaSE11PrgISG.be2.46
Which of the following statements about overridden methods are true? (Choose all that apply.)
A. An overridden method must use an access modifier that is the same or less restrictive than the method it overrides.
B. An overridden method can declare new unchecked exceptions that are not defined in the method it overrides.
C. An overridden method may refrain from declaring any or all of the exceptions as the method it overrides.
D. A method overriding another method cannot be marked final.
E. An overridden method must return the exact same type as the method it overrides.
F. A method that has a single vararg parameter may be overridden by a method that takes no arguments, as varargs can have zero-or-more parameters.
You Answered Correctly!
An overridden method must use an access modifier that is the same or less (not more) restrictive than the method it inherits, making option A correct. An overridden method can swallow (refrain from declaring) or declare new unchecked exceptions as the method it inherits, making options B and C correct. It may not declare new checked exceptions, though. Option D is correct as there is no rule that an overridden method cannot be marked final. Option E is incorrect, as the return type has to be covariant. In other words, the return type of the overridden method can be the same or a subtype as the return type of the method it overrides. Finally, option F is incorrect. If an overridden method changes the signature (the name and list of parameters) in any way, then the method is overloaded, not overridden.

It is almost a terrific question, but the off-brand usage of the terminology definitely slowed me down a lot and caused me to do several re-reads to ensure I wasn't getting tricked intentionally.  Looking at both the questions I got right and those I got wrong, there are PLENTY of very tricky ones where noticing something seeming just a tiny bit off is your only clue/hope of getting it correct.
 
Mike Simmons
Master Rancher
Posts: 4036
54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I share your frustration - the usage of "overridden" here is flat-out wrong.  Not just in terms of how the word is defined in the JLS, but also in the basic English meaning of the word.  If a leader's orders are overridden, then that means they were replaced by other orders, not that they replaced some other orders.  If A overrides B, then A is overriding, and B is overridden.

Fortunately, the wording of the question makes it clear what they meant, and at least the term was used consistently throughout the question.  Though that would then make me second-guess any other question using the term.
 
Jesse Silverman
Saloon Keeper
Posts: 1343
40
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
Thanks, I feel that with overload / overloaded it doesn't make any difference, which is kind of the whole point of overloading, they may as well just have totally different names.

Here, the directionality matters.  This stood out to me about four times as noticeably as key details on a handful of questions that I got wrong, not because I didn't know the material, but I was pushing to go faster, and glossed over said details.

Anyway, thanks!
 
Jeanne Boyarsky
author & internet detective
Posts: 40747
827
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
Ah. Overridden vs overriding!
 
Jesse Silverman
Saloon Keeper
Posts: 1343
40
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've had co-workers who constantly wrote overriding when they meant overwriting and vice versa.

Try as I might, I could never get some of them to apply these homonyms correctly.

But in this case, we are dealing with good ol' antonyms!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic