Hi,
As we know object of abstract class can't be created, Then what is main reason of it's use? Plz,help.
Thanks.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Datta KharadPosted Nov 29, 2011, 1:03 AM
You can refer these links..
http://www.c-sharpcorner.com/Forums/Thread/148684/abstract-class-and-inheritance.aspx
http://www.dotnetperls.com/abstract
Kunal NaikPosted Nov 29, 2011, 12:59 AM
Main reasons to use abstract class,
1. Abstract Classes are needed to model those objects that have no existence in the real-world but serves as a base class for several real-world objects.
2. Abstract classes can have default behavior if something sensible is possible.
3. Abstract classes can have state that's shared with all subclasses.
also see below link,
http://www.headspring.com/2011/07/two-reasons-to-use-abstract-classes-in-c
http://www.c-sharpcorner.com/interviews/answer/2269/
may be it helps you.
Pravin MorePosted Nov 29, 2011, 12:51 AM
Hi Alok,
An abstract class cannot be instantiated as an object and is only provided for the purpose of deriving subclasses. a base class is not intended to be instantiated and is provided solely for the purpose of providing an outline for subclasses.
for e.g:-
abstract class absClass1
{
public abstract int AddTwoNumbers(int Num1, int Num2);
public abstract int MultiplyTwoNumbers(int Num1, int Num2);
}
abstract class absClass2:absClass1
{
//Implementing AddTwoNumbers
public override int AddTwoNumbers(int Num1, int Num2)
{
return Num1+Num2;
}
}
Thanks,
Pravin
Hemant KumarPosted Nov 29, 2011, 12:19 AM
An abstract type is defined largely as one that can't be created. You can create subtypes of it, but not of that type itself. The CLI will not let you do this.
An
abstractclass has aprotectedconstructor (by default) allowing derived types to initialize it.For example, the base-type
Streamis abstract. Without a derived type where would the data go? What would happen when you call anabstractmethod? There would be no actual implementation of the method to invoke.