The "Inherits" keyword can be used to make one class inherit from another class's properties, methods, events, and so on, and all classes can be inherited by default unless they are set to the "noinheritable" keyword.
The following example defines two classes, the first class is a base class, and contains a property and two methods, the second class inherits the property and two methods from the first class, overloads the second method, and defines a new property "IntProp2".
Class Class1
Private intProp1 as Integer
Sub Method1 ()
MessageBox.Show ("This is a method in the base class") End
Sub
Overridable Sub Amethod ()
MessageBox.Show ("This is another method in the base class") End
Sub property
Prop1 as Integer get
PROP1=INTPROP1
End to
set
Intprop1=value end
Set End
class
class Class2
Private IntProp2 As Integer
Inherits Class1 property
Prop2 As Integer
get
prop2=intprop2
End Get
Set
Intprop2=value End Set End Property
Overrides Sub amethod ()
MessageBox.Show ("This is a method in an inheriting class") End
Sub
End Class
Protected Sub testinheritance ()
Dim C1 As New Class1 ()
Dim C2 As New Class2 () C1
. Method1 ()
c2.amethod ()
C2. METHOD1 () End
Sub
After the user runs the process textinheritance, you can see the following information:
"This is a method in the basic class."
"This is another method in the basic class."
"This is a method in the basic class."
"This is a method in the inheriting class"