Rules for vb.net inheritance

Source: Internet
Author: User
Tags expression inheritance modifier

The user can use a new keyword "inherts" to build a new class based on a basic class, the inheriting class can inherit, extend the properties, methods, events, data members, and event handlers of the base class.
VB.net introduces the following expressions to support the expression of inheritance:
(1) Inherits statement--used to show that the current class is inheriting which already existing class (base class), inherits can only be used in the class.
(2) Notinheritalbe modifier--prevents a program from taking a class as a basic class.
(3) MustInherit modifier--declares that this class is not created and must be inherited, and that the only way to use that class is to inherit it.
The new inherited class can overload some basic methods, vb.net using the following keywords to control the overloads of properties and methods:
(1) overridable--allows a property or method to be overloaded in an inherited class. The default value for a public method is NotOverridable.
(2) overrides--allows the user to overload a property of a basic class or a method.
(3) NotOverridable (default)-Prevents a property or method from being overloaded in an inherited class.
(4) mustoverride--When this keyword is used, the class that needs to be inherited must be overloaded with the property or method, where the expression of the method includes only sub,function or properties.
Note: Other descriptions are not allowed, and there is no end Sub or End Function description. Classes that have MustOverride methods must be declared as MustInherit, and the default value of the public method is NotOverridable.
And with respect to inheritance, there are the following guidelines:
(1) Although an inheriting class can inherit from only one class, it can produce countless interfaces.
(2) A public class cannot inherit a friend or private class, and a friend class cannot inherit a private class.
1. Ways to access Basic classes using MyBase
When a user overloads a method of a base class in an inherited class, you can use MyBase to invoke the method in the base class, and the following statement gives the user a more detailed description of the MyBase.
(1) MyBase is a reference to the basic class and its inherited members.
(2) Some of the methods defined in the MyBase, there is no need to define it in MyBase, it can be defined indirectly in an inheritance class, and for the MyBase to be properly referenced and compiled, some underlying classes must include a method that matches its parameter name and type when referenced.
(3) MyBase cannot be used to qualify itself, so the following description is incorrect:
MyBase.MyBase.BtnOK_Click ()
(4) MyBase is a key word.
(5) MyBase cannot be used as a variable or process, or in "is" comparisons, MyBase is not a real object.
(6) MyBase can be used as a shared member, and it is valued because shared members can be shadowed.
(7) MyBase cannot be used in modules.
2. Use of MyClass
(1) MyClass allows you to invoke a method that can be overloaded, and to confirm that the call is a implementation process in the method, rather than an overloaded method in the inherited class, the following methods are valid, and the method used to qualify a method in a class with MyClass is defined in the basic class , but there is no definition of this method in this class. This reference has the same meaning as Mybase.method.
(2) MyClass is a key word.
(3) MyClass cannot be used as a variable, or as a procedure, or in a "is" comparison, MyClass is not a real object.
(4) MyClass can reference the contained class and its inherited members, and can be used as access to public members defined in the class, but cannot access private members in the class.
(5) MyClass can be used as a qualification for shared members.
(6) MyClass cannot be used in standard modules.

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.