Classes - in COBOL and C# and VB.NET

C# COBOL VB.NET
// Static class, no instances possible
internal static class Utils
{
public static int Square(int x)
{
return x * x;
}
}
// Abstract class
public abstract class Shape
{
protected abstract int Area { get; }
public override string ToString()
{
return $"Area = {Area}";
}
}
// Sub class
public class Rectangle : Shape
{
public virtual int Width { get; set; }
public virtual int Height { get; set; }
protected override int Area => Width * Height;
}
// Sub class of a sub class
public class Square : Rectangle
{
public int Size { get; set; }
public override int Width
{
get => Size;
set => Size = value;
}
public override int Height
{
get => Size;
set => Size = value;
}
protected override int Area => Utils.Square(Size);
public override string ToString()
{
return "Square, " + base.ToString();
}
}
*> Static class, no instances possible
class-id Utils internal static.
method-id Square (x as binary-long)
returning return-value as binary-long static.
set return-value to x * x
end method.
end class.
*> Abstract class
class-id Shape public abstract.
01 #Area binary-long property protected abstract.
method-id ToString returning return-value as string override.
set return-value to "Area = " & self::Area
end method.
end class.
*> Sub class
class-id Rectangle public inherits type Shape.
01 #Width binary-long property.
01 #Height binary-long property.
property-id #Area binary-long override.
getter.
set property-value to #Width * #Height
end property.
end class.
*> Sub class of a sub class
class-id Square public inherits type Rectangle
01 #Size binary-long property.
property-id #Width binary-long override.
getter.
set property-value to #Size
setter.
set #Size to property-value
end property.
property-id #Height binary-long override.
getter.
set property-value to #Size
setter.
set #Size to property-value
end property.
property-id #Area binary-long override.
getter.
set property-value to type Utils::Square(#Size)
end property.
method-id ToString returning return-value as string override.
set return-value to "Square, " & super::ToString()
end method.
end class.
' Static class, no instances possible
Friend Module Utils
Public Function Square(x As Integer) As Integer
Return x * x
End Function
End Module
' Abstract class
Public MustInherit Class Shape
Protected MustOverride ReadOnly Property Area As Integer
Public Overrides Function ToString() As String
Return $"Area = {Area}"
End Function
End Class
' Sub class
Public Class Rectangle
Inherits Shape
Public Overridable Property Width As Integer
Public Overridable Property Height As Integer
Protected Overrides ReadOnly Property Area As Integer
Get
Return Width * Height
End Get
End Property
End Class
' Sub class of a sub class
Public Class Square
Inherits Rectangle
Public Property Size As Integer
Public Overrides Property Width As Integer
Get
Return Size
End Get
Set (value As Integer)
Size = value
End Set
End Property
Public Overrides Property Height As Integer
Get
Return Size
End Get
Set (value As Integer)
Size = value
End Set
End Property
Protected Overrides ReadOnly Property Area As Integer
Get
return Utils.Square(Size)
End Get
End Property
Public Overrides Function ToString() As String
Return "Square, " & MyBase.ToString()
End Function
End Class