Skip to content

Instantly share code, notes, and snippets.

@pjastr
Created December 10, 2017 11:17
Show Gist options
  • Save pjastr/5058fd7b27c3b87883b4d2deb065ee6c to your computer and use it in GitHub Desktop.
Save pjastr/5058fd7b27c3b87883b4d2deb065ee6c to your computer and use it in GitHub Desktop.

Przeanalizuj poniższy kod:

public class A
{
   public void NormalFun() { Console.WriteLine("A NormalFun()"); }
   public virtual void VirtualFun() { Console.WriteLine("A VirtualFun()"); VirtualFun2();}
   public virtual void VirtualFun2()  { Console.WriteLine("A VirtualFun2()"); }
}
 
public class B : A
{
   public void NormalFun() { Console.WriteLine("B NormalFun()"); }
   public virtual void VirtualFun() { Console.WriteLine("B VirtualFun()"); }
   public override void VirtualFun2() { Console.WriteLine("B VirtualFun2()"); }
}
 
public class C : B
{
   public override void VirtualFun() { Console.WriteLine("C VirtualFun()"); }
}
 
public class D : C
{
   public void NormalFun() { Console.WriteLine("D NormalFun()"); }
   public override void VirtualFun() { Console.WriteLine("D VirtualFun()"); }
   public override void VirtualFun2() { Console.WriteLine("D VirtualFun2()"); }
}
 
public abstract class E : D
{
   public virtual void VirtualFun() {  Console.WriteLine("E VirtualFun()"); }
   public abstract void VirtualFun2();
}
 
public class F : E
{
   public override void VirtualFun() { Console.WriteLine("F VirtualFun()"); }
   public override void VirtualFun2() { Console.WriteLine("F VirtualFun2()"); }
}

Źródło: https://www.p-programowanie.pl/c-sharp/metody-wirtualne-abstrakcyjne-i-polimorfizm/#Zaawansowane-dziedziczenie-i-polimorfizm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment