Saturday, June 9, 2012

Abstract Class in C# ?

Abstract class:

it contains mixure of concrete methods in the sense methods with body and some methods only names.

when a class contains an anstract method the class is called abstract class.to define an abstract method it uses "abstract" keyword.

if a class contains an abstract method then the class must be defined with "abstract" keyword.

to redefined an abstract method the derived class uses "override" keyword.

NOTE: AN ABSTRACT CLASS COULDN'T HAVE OBJECT REFERENCE WHY BECAUSE IT IS WITH SOME METHODS WITHOUT COMPLETION.


class Program
{
static void Main(string[] args)
{
MyClass c = new MyClass();
c.disp();
c.print();
Console.ReadLine();
}
}

//abstract class
abstract class MyAbstractClass
{
public void print()
{
Console.WriteLine("print method");
}
public abstract void disp();
}
//derived class
class MyClass:MyAbstractClass
{
public override void disp()
{
//throw new NotImplementedException();
Console.WriteLine("this is disp method");
}
}
============