Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

i am princes

please clear my doubt
Posted

The whole point of an abstract class is that it is not intended to be instantiated - that you can't create an object of that type. Instead, it is intended to provide a "framework" on which actual instances can be built.

For an example, think about cars: A Car is an abstract type: you never buy "A car" - you buy "A Ford Fiesta" or "A Ferrari 458", but they both derive from the base "Car" class, and they have "Car" properties and methods in common: four wheels, somewhere for the driver to sit, steering, engine, and so on. You can jump into any Car derived object and expect to be able to steer it (at least around a car park).
So the abstract Car class might have:
C#
public abstract Car
   {
   public abstract void StartEngine();

   public override TurnLeft(float degrees)
      {
      Turn(degrees);
      }
   public override TurnRight(float degrees)
      {
      Turn(-degrees);
      }
   }
Which would require you to create a SatrtEngine method, but you can optionally cretae your own TurnLeft and TurnRight methods.

There is a lot to think about with abstract classes, so try having a look at the MSDN documentation first: http://msdn.microsoft.com/en-gb/library/sf985hc5.aspx[^]
 
Share this answer
 
Comments
Rob Philpott 12-Jul-14 4:45am    
Hmm. I'd argue that you can buy a car. That example is like saying you can have an abstract book class from which every book derives - that would be a lot of subclasses! Instance data, not derived classes.
Richard MacCutchan 12-Jul-14 5:02am    
You can only buy a specific instance of a car, there is not, to my knowledge, any manufacturer that produces a "car".
OriginalGriff 12-Jul-14 5:06am    
You don't buy "a car" and drive off in it: you buy a specific instance of a specific model, of a specific manufacturer's car. What you bought was "a car", but that isn't specific enough to buy a spare part for! :laugh:
No, an abstract class is just that: abstract. It cannot be created since there are parts of it that are not fully defined. An abstract class may only be used as the base for a real or concrete class.
 
Share this answer
 
Abstract Class can't be instantiated but we can inherit Abstract class.
For more information see http://www.dotnet-tricks.com/Tutorial/csharp/E0K2011113-A-Deep-Dive-into-C[^]
 
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