• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Abstract class- sudden confusion

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if super class is abstract, then shd all the subclasses override all the abstract methods?
I think the answer is yes.
whether the subclass is providing implementation or not , all the superclass shd override all the abstract methods.
Please give me your comments.

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to instantiate the subclass object and use any method in it.. then yes, you must implement all the methods of the abstract superclass
------------------
www.tipsmart.com
 
padmini Babu
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sandeep,
Thanks for the answer.
I do understand that if the subclass does not provide any implementation of any of the superclass's abstract methods then the subclass must also be declared abstract.
But my question still remains unanswered.
-- It is whether we have to override all the abstract methods of the superclass whether or not we provide implementation.
Thanks once again
Padmini
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think if a class extends an abstract class it has to override all the methods and has to implement all of them. If you don't implement the method, the compiler will ask you to declare the class to be abstract.
Please correct me if i am wrong.
Vanitha.
[This message has been edited by Vanitha Sugumaran (edited June 24, 2001).]
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi padmini,
You have to override all the abstract methods but can you don't have to implement them; you can provide an empty body

The above will compile without any errors.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
padmini Babu
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jane Griscti:
[B]Hi padmini,
You have to override all the abstract methods but can you don't have to implement them; you can provide an empty body
___________________________________
Thanks Jane and Vanitha
I am clear.
Padmini

[This message has been edited by padmini Babu (edited June 24, 2001).]

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jane,
When you say, "provide an empty body", does not it mean u are implementing the method?
Albert
===================================================

Originally posted by Jane Griscti:
[B]Hi padmini,
You have to override all the abstract methods but can you don't have to implement them; you can provide an empty body

The above will compile without any errors.
Hope that helps.
[/B]


 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was thinking of 'implementing' in the sense that the method will actually 'do' something. If it has an empty body it isn't doing anything.
Technically though you're probably right. If the modifier 'abstract' is not included in the declaration, even if it has an empty body the compiler will view it as being implemented.

------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the subclass is also an abstract class then you don't have to override all of the abstract methods of superclass.
For example following code compiles fine(JVM 1.3)

Thanks

Originally posted by padmini Babu:
Hi Sandeep,
But my question still remains unanswered.
-- It is whether we have to override all the abstract methods of the superclass whether or not we provide implementation.


 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic