abstract class absClass
{
public int AddTwoNumbers(int Num1, int Num2)
{ return Num1 + Num2; }
public abstract int MultiplyTwoNumbers(int Num1, int Num2);
}
//A Child Class of absClass
class absDerived : absClass
{
[STAThread]
static void Main(string[] args)
{
//You can create an instance of the derived class
absDerived calculate = new absDerived();
int added = calculate.AddTwoNumbers(10, 20);
int multiplied = calculate.MultiplyTwoNumbers(10, 20);
Console.WriteLine("Added : {0}, Multiplied : {1}", added, multiplied);
}
public override int MultiplyTwoNumbers(int Num1, int Num2)
{ return Num1 * Num2; }
}
}
An abstract class can contain either abstract methods or non abstract methods. Abstract members do not have any implementation in the abstract class, but the same has to be provided in its derived class.
An abstract class does not mean that it should contain abstract members. Even we can have an abstract class only with non abstract members.
An abstract class cannot be a sealed class.
Declaration of abstract methods are only allowed in abstract classes.
An abstract method cannot be private.
An abstract member cannot be static.
The access modifier of the abstract method should be same in both the abstract class and its derived class. If you declare an abstract method as protected, it should be protected in its derived class. Otherwise, the compiler will raise an error.An abstract method cannot have the modifier virtual. Because an abstract method is implicitly virtual.
Raja123, if this helps please login to Mark As Answer. | Alert Moderator