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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Hemant KumarRank #1,202 · 1.5K reputationPosted Nov 28, 2011, 7:19 PM EST
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.Pravin MoreRank #1,419 · 1.2K reputationPosted Nov 28, 2011, 7:51 PM EST
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
Kunal Naik163 reputationPosted Nov 28, 2011, 7:59 PM EST
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.
Datta KharadRank #2,135 · 668 reputationPosted Nov 28, 2011, 8:03 PM EST
You can refer these links..
http://www.c-sharpcorner.com/Forums/Thread/148684/abstract-class-and-inheritance.aspx
http://www.dotnetperls.com/abstract