To open the possibility for subclass to reimplement members from interface we can add virtual keyword to the implementation.
using System;
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:
shape
rectangle| w_ww_.j___a__v_a___2_s___._c_o___m__ | Contact Us |
| Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
| All other trademarks are property of their respective owners. |