Win a copy of Microservices in Action this week in the Web Services 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Sybex OCA Chapter 5 #15 Errata?  RSS feed

 
Ranch Hand
Posts: 232
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q: Which of the following is true about a concrete subclass? (Choose all that apply)
A. A concrete subclass can be declared as abstract.
B. A concrete subclass must implement all inherited abstract methods.
C. A concrete subclass must implement all methods defined in an inherited interface.
D. A concrete subclass cannot be marked as final.
E. Abstract methods cannot be overridden by a concrete subclass.


A concrete class must implement all inherited abstract methods, so option B is correct. Option C is incorrect; a superclass may have already implemented an inherited interface, so the concrete subclass would not need to implement the method.




Why does C's (incorrect answer) provided explanation somehow not apply to B?  Asked differently, how is B correct while C is not?  Seemingly to me, both B and C potentially suffer from C's explanation?  (Although not a choice, the answer should be none of the above?)
 
author & internet detective
Posts: 38925
686
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charles,
Suppose you have three classes: Shape, Rectangle and Square.

Shape is an abstract class and has abstract methods name(), perimeter() and area().

Rectangle extends Shape and implements perimeter() and area(). It does not implement name().

Square extends Rectangle. It needs to implement name(). It does not need to implement perimeter() and area() because they are implemented by the superclass. So they are not abstract from Square's point of view. So B is correct.

By contrast, in an interface, all the methods are abstract. (on the OCA this is true. On the OCP, you have static/default methods too)

Does this help?
 
Charles O'Leary
Ranch Hand
Posts: 232
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne!

If Square extends the concrete class ChildRectangle, which extends Rectangle thus it (ChildRectangle) implements name(). Here, Square would not need to implement perimeter(), area(), nor name() because of Square's ChildRectangle and Rectangle parents.   So none of the aforementioned methods would be abstract from Square's point of view.  B would not be correct in this context?  

Do you see the point I'm trying to make?  The book's "final" answer reminds me of why (in in the book) you mentioned in practice, that you don't necessarily want to mark classes (or answers in this case?) as "final" (paraphrasing) ... you don't know all the permutations that may need to later come.

Thanks,
Charles
 
Jeanne Boyarsky
author & internet detective
Posts: 38925
686
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Charles O'Leary wrote:.  B would not be correct in this context?  


B would still be correct in this scenario. There are no abstract methods so therefore they are "all" implemented.

I was trying to give an example where C is wrong and B is right.
 
Charles O'Leary
Ranch Hand
Posts: 232
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne,

B. A concrete subclass must implement all inherited abstract methods.

Despite the fact that age is inaccessible by the child class, if we have an instance of a Lion object, there is still an age value that exists within the instance. The age value just cannot be directly referenced by the child class nor any instance of the class. In this manner, the Lion object is actually “bigger” than the Animal object in the sense that it includes all the properties of the Animal object (although not all of those properties may be directly accessible) along with its own set of Lion attributes.



I guess I'm trying to say that B can potentially be "interpreted" as being ruled out by some readers because the word first is (purposefully?) missing?  Indeed, Square is a (non-first) concrete subclass that must not implement all inherited abstract methods?  Square is a larger object than it's predecessors, and there really are three inherited abstract methods in Square's entire family tree?  Another alternate, "B. A concrete subclass must implement all inherited abstract methods of its direct/immediate parent class"?

Can't wait to hear your thoughts!

Thanks,
Charles
 
Jeanne Boyarsky
author & internet detective
Posts: 38925
686
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not purposefully omitted. It's one of those "English is less precise than code" problems.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!