Home
Browse all 647 examples
Download all 647 examples
Download sample chapters
Reviews
Errata
Acknowledgments
Links on .NET
Paradoxal Press

Buy directly from Paradoxal Press at $33.99 (Save 43%)



Category: Programming
Level: Beginner to seasoned
900 pages
ISBN-10 097661322-0
ISBN-13 978-097661322-0
$59.99 USA
$79.99 CANADA


Listing 12-12 extracted from chapter Inheritance, polymorphism and abstraction


Listing 12-11<     > Listing 12-13


This listing can be compiled with the command line:
csc.exe /target:exe Example_12_12.cs
Errors: 0 Warnings: 0


Example_12_12.cs
interface I {
   void f(int i);
   void g(int i);
}
class FooBase : I {
   public virtual void f(int i) {
      System.Console.WriteLine("FooBase.f({0})", i);
   }
   public void g(int i) {
      System.Console.WriteLine("FooBase.g({0})", i);
   }
}
class FooDerived : FooBase {
   public override void f(int i) {
      System.Console.WriteLine("FooDerived.f({0})", i);
   }
}
class Program {
   static void Main() {
      FooBase  refB1 = new FooBase();
      I        refI1 = refB1;
      FooDerived refD= new FooDerived();
      FooBase  refB2 = refD;
      I        refI2 = refD;
      refB1.f(1);
      refI1.f(2);
      refD.f(3);
      refB2.f(4);
      refI2.f(5);
   }
}	
Copyright Patrick Smacchia 2006 2007