wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overriding a method with an abstract version Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriding a method with an abstract version" Watch "Overriding a method with an abstract version" New topic
Author

Overriding a method with an abstract version

Francisco Montes
Ranch Hand

Joined: Sep 30, 2009
Posts: 30
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


SCJP 1.6
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525

Note that the overridden class can be concrete also.
... Jim ...

BEE MBA PMP SCJP-6
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jan 09, 2008
Posts: 525
Okay Paul. I was just trying to stay in the moment . . .
... Jim ...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Nov 04, 2009
Posts: 2066

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.,


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Francisco Montes
Ranch Hand

Joined: Sep 30, 2009
Posts: 30
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

Joined: Jan 09, 2008
Posts: 525
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overriding a method with an abstract version
 
Similar Threads
abstract method implementation
Overriding and Exceptions - Examlab question
Can we mark an overriding method as abstract
Question about overriding : from ExamLab practice test no 2
Exam Lab Question