C#
|
VB.net
|
using System;
public class GrandFather
{
public virtual void Method()
{
Console.WriteLine("I'm from GrandFather");
}
}
|
Public Class GrandFather
Public Overridable Sub Method()
Console.WriteLine("I'm from GrandFather")
End Sub
End Class
|
public class Father : GrandFather
{
public override void Method()
{
Console.WriteLine("I'm from Father");
}
}
|
Public Class Father
Inherits GrandFather
Public Overrides Sub Method()
Console.WriteLine("I'm from Father")
End Sub
End Class
|
public class Son : Father
{
public sealed override void Method()
{
Console.WriteLine("I'm from Son");
}
}
|
Public Class Son
Inherits Father
Public Overrides NotOverridable Sub Method()
Console.WriteLine("I'm from Son")
End Sub
End Class
|
public class GrandSon : Son
{
public new void Method()
{
Console.WriteLine("I'm from GrandSon");
}
}
|
Public Class GrandSon
Inherits Son
Public Shadows Sub Method()
Console.WriteLine("I'm from GrandSon")
End Sub
End Class
|
internal class Program
{
private static void Main(string[] args)
{
GrandFather gf = new GrandFather();
gf.Method();
GrandFather f = new Father();
f.Method();
GrandFather s = new Son();
s.Method();
GrandFather gs = new GrandSon();
gs.Method();
Console.ReadKey();
}
}
|
Friend Class Program
Private Shared Sub Main(args As String())
Dim gf As New GrandFather()
gf.Method()
Dim f As GrandFather = New Father()
f.Method()
Dim s As GrandFather = New Son()
s.Method()
Dim gs As GrandFather = New GrandSon()
gs.Method()
Console.ReadKey()
End Sub
End Class
|
Output:
I'm from GrandFather
I'm from Father
I'm from Son
I'm from Son
|
|