Use Interface: Sub TestInterface () Dim RectangleObject2 As New RectangleClass2 () Dim RightTriangleObject2 As New RightTriangleClass2 () ProcessShape2 (RightTriangleObject2, 3, 14) ProcessShape2 (RectangleObject2, 3, 5) End Sub Sub ProcessShape2 (ByVal Shape2 As Shape2, ByVal X As Double, Byval Y as double) MessageBox.show ("The area of the object is" & shape2.calculateArea (x, y)) End Sub 'The same interface can be handled by the same method. class
Public Interface Shape2 Function CalculateArea (Byval X as Double, Byval Y as double) As Doublend Interface
Public Class RightTriangleClass2 Implements Shape2 Function CalculateArea (ByVal X As Double, ByVal Y As Double) As Double Implements Shape2.CalculateArea 'Calculate the area of a right triangle. Return 0.5 * (X * Y) End FunctionEnd Class
Public Class RectangleClass2 Implements Shape2 Function CalculateArea (ByVal X As Double, ByVal Y As Double) As Double Implements Shape2.CalculateArea 'Calculate the area of a rectangle. Return X * Y End FunctionEnd Class