Click here to Skip to main content
16,005,038 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
What is an abstract class? How it will used in realtime?
Posted
Comments
Dalek Dave 26-Aug-10 5:18am    
Reading and Googling are skills to be learnt.
Toli Cuturicu 26-Aug-10 6:16am    
Reason for my vote of 1
google
Smithers-Jones 26-Aug-10 7:21am    
Reason for my vote of 1
What is Google?
Sandeep Mewara 26-Aug-10 13:45pm    
Reason for my vote of 1
Google?

There are numerous articles on abstract classes available on the internet. See here[^].

You could also try reading a book.
 
Share this answer
 
v2
Comments
senguptaamlan 26-Aug-10 2:04am    
absolutely right...you need to learn and need to conceive the idea only after that you can understand the place where you can actually fit the abstract class and abstractions. Got a good article, please go through the following links
http://www.c-sharpcorner.com/uploadfile/eecabral/oopsand.net211102005075520am/oopsand.net2.aspx

This link is for GOF Patterns
http://msdn.microsoft.com/en-us/magazine/cc188707.aspx
Every (every!) good Object Oriented Programming book will tell you. Please read a book.
:)
 
Share this answer
 
Abstraction: It is defined as Wrapping up the Data into Single Unit.

Abstract Classes: are defined as the Classes Which provide the abstract methods (1 or more) in the base class which can be overriden in the child class and abstract class cannot be instantiated. Overriding the Abstract methods in the derived class is mandatory.
 
Share this answer
 
v2
Abstract classes cannot be instanciated themselves. They are used to provide a base structure or base implementation (or part implementation) for other classes.

See these examples:
C#
// Pointless abstract class
abstract class A
{

}
// All derived classes will have ID property and DoSomething method.
abstract class B
{
    private int id;

    public int ID
    {
        get { return id; }
        set { id = value; }
    }

    public void DoSomething()
    {
        Console.WriteLine("Doing it!");
    }
}
// All derived classes will have ID property and DoSomething method but they will have to implement them themselves
abstract class C
{
    public abstract int ID { get; set; }
    public abstract void DoSomething();
}
// All derived classes will have DoSomething method but they can chose to implement it themselves or use this implementation
abstract class D
{
    public virtual void DoSomething()
    {
        Console.WriteLine("Doing it!");
    }
}
// All derived classes can access InitialValue but it will not be available to non derived classes
abstract class E
{
    protected const int InitialValue = 5;
}
// All derived classes must call this class's constructor from their constructor passing an id value - see FUseage
abstract class F
{
    private int id;

    protected F(int id)
    {
        this.id = id;
    }

    public int ID
    {
        get { return id; }
        set { id = value; }
    }
}
class FUseage : F
{
    public FUseage()
        : base(0)
    { }
}
 
Share this answer
 
v2
abstract class is served as base class for other class, it means that other classes can inherit it. :)
 
Share this answer
 
v2
Comments
Toli Cuturicu 26-Aug-10 6:18am    
Reason for my vote of 3
correct but poor
CPallini 27-Aug-10 3:34am    
Reason for my vote of 3
Not complete.

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