Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand VB.NET inheritance rules

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to understand VB.NET inheritance rules, I believe that many inexperienced people do not know what to do. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

There are inheritance related technologies in VB.NET, and it is not easy to understand this application compared to beginners. First of all, let's learn from the VB.NET inheritance rules to understand the basic concepts of this application, so as to facilitate our further study in the future.

Users can use a new keyword "Inherts" to build a new class based on a basic class, and the inherited class can inherit and extend the properties, methods, events, data members and event handlers of the basic class.

VB.NET introduces the following statements to support the expression of VB.NET inheritance rules:

(1) Inherits statement-used to indicate which existing class the current class inherits (the basic class). Inherits can only be used in the class.

(2) NotInheritalbe modifier-- prevents programs from using a class as a base class.

(3) MustInherit modifier-- declares that this class cannot be created and must be inherited, and the only way to use this class is to inherit it.

The new inherited class can overload some basic methods, and VB.NET uses the following keywords to control the overloading of properties and methods:

(1) Overridable-- allows a property or method to be overloaded in an inherited class. The default value of the common method is NotOverridable.

(2) Overrides-- allows users to overload the properties or methods of a base class.

(3) NotOverridable (default)-prevents a property or method from being overloaded in an inherited class.

(4) MustOverride-- when the keyword is used, the class that needs to inherit must overload the property or method, in which the representation of the method only includes Sub,Function or Property.

Note: other descriptions are not allowed, there are no End Sub or End Function descriptions. Classes with MustOverride methods must be declared as MustInherit, and the default value for public methods is NotOverridable. And for inheritance, there are also the following VB.NET inheritance rules:

(1) although an inherited 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. Methods for accessing basic classes using Mybase

When the user overloads the methods of the base class in the inheritance class, they can use Mybase to call the methods in the base class, and the following statement will provide the user with some more detailed description of Mybase.

(1) MyBase is a reference to the base class and its inherited members.

(2) some methods qualified in MyBase do not need to be defined in Mybase; they can be defined indirectly in inherited classes. In order for Mybase to be referenced and compiled correctly, some underlying classes must include a method that matches their parameter names and types when referenced.

(3) Mybase cannot be used to qualify itself, so the following description is incorrect:

MyBase.MyBase.BtnOK_Click ()

(4) MyBase is a keyword.

(5) MyBase cannot be used as a variable or procedure, or as a "IS" comparison, MyBase is not a real object.

(6) MyBase can be used as a shared member (shared members); it has a value because the shared member can be shadowed.

(7) MyBase cannot be used in the module.

two。 Use MyClass

(1) MyClass allows you to call a method that can be overloaded, and confirm that you are calling the implementation procedure in the method, rather than inheriting the overloaded method in the class. The following method is legal in the VB.NET inheritance rules, using MyClass to define a method in a class. This method is defined in the base 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 keyword

(3) MyClass cannot be used as a variable, or as a procedure, or as a "Is" comparison. MyClass is not a real object.

(4) MyClass can reference the included class and its inherited members, and can be used to access the public members defined in the class, but not the private members of the class.

(5) MyClass can be used as a qualification for shared members.

(6) MyClass cannot be used in standard modules.

After reading the above, have you mastered how to understand the VB.NET inheritance rules? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report