Abstract classes are those classes, which create using Abstract Keyword. Abstract class contains both Abstract method and Non Abstract Method. Abstract Methods are those methods, which is only declared not defined. We cannot create the object of Abstract Class. We have to inherit abstract class in another class and define the abstract methods.
In the following example, we have created Abc class which is Abstract class and Pqr Class in which we inherit Abc class. In Abstract class, we have created two methods sum and sub. In Abc class sub is our abstract method which is only declared not define. In Pqr class, we have defined sub method using override keyword.
public abstract class Abc
{
public int sum(int x, int y)
{
return (x + y);
}
public abstract int sub(int x, int y);
}
public class Pqr : Abc
{
public override int sub(int x, int y)
{
return (x - y);
}
}
Now when we create the object of Pqr class and call the sub function, it will call the derived class function.
Pqr pq = new Pqr();
Response.Write( pq.sub (10, 5));