Friday, February 20, 2015

Abstract Class in C#

If we don't want a class object to be created define the class as abstract. An abstract class can have abstract and non abstract classes. If a method in abstract id defined as abstract , it must be implemented in derived class. For example , in the classes given below , method DriveType is defined as abstract. 

abstract class Car
{
public Car()
{
Console.WriteLine("Base Class Car");
}
public abstract void DriveType();
}

class Ford : Car
{
public void DriveType()
{
Console.WriteLine("Right Hand ");
}
}

No comments:

Post a Comment