virtual interface implementation
In this chapter you will learn:
virtual method for interface implementation
To open the possibility for subclass to reimplement
members from interface we can add virtual
keyword to the implementation.
using System;// ja va2 s . c om
interface Printable{
void print();
}
class Shape : Printable{
public virtual void print(){
Console.WriteLine("shape");
}
}
class Rectangle : Shape{
public override void print(){
Console.WriteLine("rectangle");
}
}
class Test
{
static void Main()
{
Shape s = new Shape();
s.print();
Rectangle r = new Rectangle();
r.print();
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Class