Use of Constructor in Abstract Class
what are the benefit of constructors or destructors in abstract class? Can be call constructor through explicitly or derived class?
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.
Sabyasachi MishraPosted Oct 13, 2015, 7:04 AM
{
//A Non abstract method
public int AddTwoNumbers(int Num1, int Num2)
{
return Num1 + Num2;
}
public AbsBaseClass()
{
Console.WriteLine("I am in Abstract class Constructor ");
}
public abstract int MultiplyTwoNumbers(int Num1, int Num2);
}
//A Child Class of absClass
class DerivedClass:AbsBaseClass
{
public DerivedClass()
{
Console.WriteLine("I am in derived class Constructor ");
}
[STAThread]
static void Main(string[] args)
{
//AbsBaseClass obj = new AbsBaseClass(); //Error as we can't create object of Abstract class
DerivedClass calculate = new DerivedClass();
int added = calculate.AddTwoNumbers(10,20);
int multiplied = calculate.MultiplyTwoNumbers(10,20);
Console.WriteLine("Added : {0}, Multiplied : {1}", added, multiplied);
Console.ReadLine();
}
//using override keyword,implementing the abstract method
public override int MultiplyTwoNumbers(int Num1, int Num2)
{
return Num1 * Num2;
}
}