• 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 does not have abstract method

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you get an answer for this in any of the forums?
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic