Click here to Skip to main content
15,889,781 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
why we use abstract classes if we can not create its instants.what is the purpose of creating abstract classes
Posted
Comments
Philippe Mori 17-Feb-12 8:59am    
If you want to do programming, you should learn to uses Google as a lot of thing are already well explained.

 
Share this answer
 
Depending upon the language implementation, there will be several answers to this question. However, while you can not create a specific instance of a virtual abstract class, you will be able to creat an instance of a class that inherits from that abstract class. Your instance now encapsulates the abstract class and all public and protected methods are available to use. It is this encapsulation that provides for software reuse and will enhance the class library's use.

Try to Google for more information on class library design. :)
 
Share this answer
 
For this kind of question Google would be a far better solution.

Why we uses abstract classes[^]

Learn This: When to use an Abstract Class and an Interface[^]

By the way, any good book on object-oriented programming should help you understand the purpose and use of abstract classes.

Generally, one would prefer interfaces to abstract classes as they are more separated from the implementation in the sense that it is much easier to reuse an interface for different classes that to reuse an abstract class particulary if the class already has a parent.

But in some cases when the class should be the base class of a family of related classes, it does make senses to uses abstract classes as it would be possible to share part of the implementation.

You cannot instantiate an abstract class but you instantiate a class that derive from one provided that you have overwrote any abstract method. This is pretty basic OOP. It allows polymorphism.
 
Share this answer
 
Because abstractions are useful, as in real life.
Consider a product. A product is an abstraction. However you don't buy a product, you buy instead an tablet, but.. Hey, that is another abastraction, you don't really buy a tablet, you buy instead that very particular tablet you have choosen. Neverthless, you don't think 'product' or 'tablet' concepts are purposeless, do you?
If you really don't like metaphors (or tablets) then have a look at "Abstract Class versus Interface"[^] CodeProject article.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900