Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding a method with an abstract version

 
Francisco Montes
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A question from ExamLab with an interesting twist (at least for me).



I thought this code would not compile. Basically because I didn´t know that a concrete method could actually be overriden by an abstract version of it.

Is not that i have a problem with this really. I guess i just have to memorize it as a new rule to learn. But i thought of sharing it with all of you too. So be warned!

Francisco
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Note that the overridden class can be concrete also.
... Jim ...
 
Paul Clapham
Sheriff
Posts: 21296
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim Hoglund wrote:
Note that the overridden class can be concrete also.
... Jim ...

That's true, but when you realize that most abstract classes extend Object -- which is a concrete class -- that observation suddenly becomes less interesting.
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay Paul. I was just trying to stay in the moment . . .
... Jim ...
 
Paul Clapham
Sheriff
Posts: 21296
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, sorry, I sort of trampled on you there didn't I? I didn't really mean it to come out that way. It's just that some ways of looking at things make the rules (or absence of rules) obvious and others don't.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Francisco Montes, What is the important of that abstract class here? I think, there s no valuable important of that abstract class AbsS in that hierarchy, rather than making a chain.,
 
Francisco Montes
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abiraman,

I was just pointing out that i never saw a concrete method being overriding by an abstract version of it. Is basically like "emptying" the concrete method and force any subclasses to implement it again. I thought that was illegal and turned out it wasn´t, that´s all.

That's true, but when you realize that most abstract classes extend Object -- which is a concrete class -- that observation suddenly becomes less interesting.


Touché Paul hehe
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe it could be used to patch a bad design; to disable a poorly
implemented method. Or when a signature is too good to give
up, but future implementations must be radically different than
what was done before . . . Further thoughts?

Jim...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic