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

What is the use of VB.NET inheritance

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces what is the use of VB. NET inheritance, has a certain reference value, interested friends can refer to, I hope you read this article after a lot of gains, the following let Xiaobian take you to understand.

In real life, children inherit their parents 'industries, which is inevitable. In programming, we often use subclasses to inherit the characteristics of their parent classes. VB. NET inheritance is a class's ability to get a parent interface or an existing parent class. When we create a new class that inherits from a parent interface or an existing parent class, we create a subclass of the original class. This is the father-son relationship as we know it.

There are many terms for inheritance, but many are redundant. The original classes, the interfaces and behaviors we inherit, can be said interchangeably:

Parent class

Superclass

Base class

VB. NET inheritance is a term used in biology. For example, dogs are canines and canines are mammals, so as canines, dogs inherit all the attributes and behaviors of mammals, which is the original meaning of inheritance, i.e. biological inheritance. The term inheritance is borrowed here for object-oriented purposes and has many similarities. In order to satisfy many programmers in VB to be able to take advantage of object-oriented functionality, especially inherited functionality, as in Visual C++, VB. NET began to have the concept of inheritance. However, VB. NET still does not allow multiple inheritance, that is, a subclass cannot have multiple parent classes inherited, it can only inherit one parent class. VB. NET allows a deep inheritance hierarchy, where a subclass can have another subclass inherit from it; however, VB. NET does not allow multiple parent classes to inherit at the same time.

In parent-child relationships, a parent object can have multiple children, all of which are inherited from the parent but of different types. For example, although a group of children are born by their parents, they still have different looks, personalities, etc.

Next, we'll look at VB. NET inheritance in detail. The value of this item should be verified to ensure that it refers to an actual product, and if possible we would also like to provide a description of the product, the code of the ProductLine class is as follows:

Public Class ProductLine Inherits LineItem Private mstrDescription As String Public ReadOnly Property Description() As String Get Return mstrDescription End Get End Property Public Sub New (ByVal ProductID As String) Item = ProductID End Sub End Class The inheritance statement we have used in the above statement: Inherits LineItem This statement enables the ProductLine class to acquire all interface elements or behaviors of the LineItem class. So we can write customer code as follows: Protected Sub Button1_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Dim pl As ProductLine pl = New ProductLine(23abc MessageBox. Show(pl.Item) MessageBox.Show(pl.Description) End Sub

The above code uses the Item attribute inherited from the LineItem class and the Description attribute in ProductLine.

Similarly, we can write ServiceLine:

Public Class ServiceLine Inherits LineItem Private mdtDateProvided As Date Public Sub New() Quantity = 1 End Sub Public Property DateProvided() As Date Get Return mdtDateProvided End Get Set mdtDateProvided = Value End Set End Property End Class

Note here that the inheritance statement above indicates that ServiceLine is a subclass of LineItem. The DateProvided property is an interface added from the LineItem class.

Thank you for reading this article carefully. I hope that the article "What is the use of VB. NET inheritance" shared by Xiaobian will be helpful to everyone. At the same time, I hope that everyone will support it a lot and pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!

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