Building an inheritance class with inheritance

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.