• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheritance of abstract classes  RSS feed

 
Swapnil Dharane
Ranch Hand
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
I know the following scenario is not practical(to be more precise,useless).Its Just out of curiosity
I have a abstract superclass which has an abstact method giveDemo()
Now I extend this class by an abstract subclass and implement giveDemo() method
Again I extend this abstract subclass and make giveDemo() method abstract
Now this is allowed.That is program compiles.
My question is how can one make an non abstract method abstract?
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can override a non abstract method to make it abstract. It will only be seen as abstract by classes that extend your class that has marked it as abstract of course.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swapnil Dharane wrote:My question is how can one make an non abstract method abstract?

I'm not quite sure what your question is:
  • Are you asking how Java implements this?
  • Or are you asking why someone might want to do it?

  • The first can probably be found in the JLS (look for something like "method dispatch"), although I warn you: it's NOT light reading.

    As to the second: Don't know.
    Sounds to me like the sort of thing you might do as an "afterthought" - ie, when you designed a class, you thought it was the only implementation you would need; but in fact it turns out not to be. You've now published the class, so you can't invert the hierarchy - which would otherwise seem to be the logical choice - without breaking existing code, so you mark the method as abstract to offer alternative choices.

    Whatever, it doesn't sound ideal to me.

    Winston
     
    Swapnil Dharane
    Ranch Hand
    Posts: 55
    Eclipse IDE
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sorry for the ambiguious question Winston
    My intention was to know how java implements it
    Can you tell me more about JSL and method dispatch.As its not light reading(as you mentioned) ,some light comments from you will be really helpful
     
    Winston Gutkowski
    Bartender
    Posts: 10575
    66
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Swapnil Dharane wrote:Sorry for the ambiguious question Winston
    My intention was to know how java implements it
    Can you tell me more about JSL and method dispatch.As its not light reading(as you mentioned) ,some light comments from you will be really helpful

    Well, this is the JLS (not JSL), which is a detailed reference of the semantics of the language and also, in some cases, also explains how things work.

    As to method dispatch, the mechanics are just not simple, so there really is no "light" way to explain it. The best description I've heard is that:
    "All non-final methods in Java are virtual"
    which, even if not strictly true, gives you a fair idea of how things work. The problem is that the description uses the word 'virtual' in the sense that C++ uses it, so you first have to know what that means.

    This chapter explains quite a lot of it, but it is very involved.

    Methinks you might spend your time better by learning good programming techniques first. Sorry if it sounds snooty, but sometimes it's just worth accepting that "things are so" and coming back to it when you have the tools to understand why.

    And actually, the scenario you describe above is very rare.

    Winston
     
    Swapnil Dharane
    Ranch Hand
    Posts: 55
    Eclipse IDE
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    fortunately I know what is a "virtual method" from c++
    Thanks for your help Winston
     
    Winston Gutkowski
    Bartender
    Posts: 10575
    66
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Swapnil Dharane wrote:Thanks for your help Winston

    You're most welcome.

    Winston
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!