Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract Class does not have abstract method

 
Arulkumar Gopalan
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
# We can have an abstract class, which does not have an abstract method.

Q: What is the purpose of having an abstract class with out having any abstract methods?

Any answer other than "to avoid creating instance for that class" is appreciated.
[ July 28, 2005: Message edited by: Arulkumar Gopalan ]
 
Lalitha Vydyula
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Arul,
Thats a good question.
A class can be declared abstract even if it does not actually have any abstract methods. Declaring such a class abstract indicates that the implementation is somehow incomplete and is meant to serve as a superclass for one or more subclasses that will complete the implementation. Such a class cannot be instantiated.
 
Arulkumar Gopalan
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for trying on my Q.

Declaring such a class abstract indicates that the implementation is somehow "incomplete"


What is a possible case for incompletion of an abstract class which does not have abstract methods?

Am asking in real implementation perspective.
[ July 28, 2005: Message edited by: Arulkumar Gopalan ]
 
Georgy Bolyuba
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arulkumar Gopalan:
Thanks for trying on my Q.


What is a possible case for incompletion of an abstract class which does not have abstract methods?

Am asking in real implementation perspective.


Maybe you choose wrong forum in that case? I think you sould ask it in OOP forum.
 
latha yeduguri
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you get an answer for this in any of the forums?
 
Devender Thareja
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arulkumar Gopalan:
# We can have an abstract class, which does not have an abstract method.

Q: What is the purpose of having an abstract class with out having any abstract methods?

Any answer other than "to avoid creating instance for that class" is appreciated.

[ July 28, 2005: Message edited by: Arulkumar Gopalan ]


The only answer is "To avoid creating instance for that class".
There is no other purpose.
 
Arulkumar Gopalan
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I was not convinced that abstract should be used for that, instead of achieving it's original concept of polymorphism.

But, I understand now, that("To avoid creating instance of a class") could be the only answer from the below explanation.

Sometimes, a class that you define represents an abstract concept and, as such, should not be instantiated. Take, for example, food. Have you ever seen an instance of food? Probably not. What you see instead are instances of carrot, apple, and chocolate chip cookies. Food represents the abstract concept of what we can eat. It doesn't make sense for an instance of food to exist.

thx.
[ July 29, 2005: Message edited by: Arulkumar Gopalan ]
 
Arulkumar Gopalan
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having said abstract key word is used only for "to avoid creating instance of a class". But, below explanation says, that should be achieved using private constructor, not through abstract.

A class type should be declared abstract only if the intent is that subclasses can be created to complete the implementation. If the intent is simply to prevent instantiation of a class, the proper way to express this is to declare a constructor (�8.8.10) of no arguments, make it private, never invoke it, and declare no other constructors. A class of this form usually contains class methods and variables. The class Math is an example of a class that cannot be instantiated; its declaration looks like this:


This is just FYI!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic