Abstract classes can contain abstract methods also. Abstract methods are the ones where only signature is available in the base class and their implementation is taken care in derived classes.
Following is an example of abstract class:
Public MustInherit Class ClassAbs Public Sub ExampleMethod() MessageBox.Show("This is sample") End Sub Public MustOverride Sub ExampleMethod_ShouldBeInherited() Public Overridable Sub ExampleMethod_CanBeCalledFromBase() MessageBox.Show("This is sample") End Sub End Class
the class contains one Abstract method
The class can be inherited as shown below:
Public Class ClassDerivedFromAbstract Inherits ClassAbs Public Sub ExampleAbstract() MyBase.ExampleMethod_CanBeCalledFromBase() End Sub Public Overrides Sub ExampleMethod_ShouldBeInherited() End Sub Public Overrides Sub ExampleMethod_CanBeCalledFromBase() MessageBox.Show("This is sample from Derived") End Sub End Class
The class can be used as shown below:
Dim CAb As New ClassDerivedFromAbstract CAb.ExampleMethod_CanBeCalledFromBase() CAb.ExampleMethod_ShouldBeInherited()
the first call uses the method from the base class and the second one uses the Method we had overriden in the derived class
No comments:
Post a Comment