Saturday, October 27, 2007

Abstract class

à Abstract class defines functionality that is implemented by one or more subclass.
à Abstract class states “what” to do, rather than “how” to do.
à Abstract class cannot be instantiated.
à Abstract method “must” be overridden in derived class.
à Abstract classes can provide all, some, or none of the actual implementation of a class.
It provides a default code or stub for their child class.à It is useful while creating Component.
Eg:abstract class shape{void draw() { }}
class circle : shape

{
void draw()
{
Console.WriteLine(“Circle”);
}
}
class rectangle : shape

{
void draw()
{
Console.WriteLine(“rectangle”);
}
}
class triangle : shape

{
void draw()
{
Console.WriteLine(“triangle”);
}
}
static void main()

{
shape s;
s = new circle();
s.draw();s = new rectangle();
s.draw();s = new triangle();
s.draw();
}
//Outputcirclerectangletriangle

No comments:

Loading...