In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to carry out VB.NET inheritance to achieve polymorphic applications, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.
As an object-oriented programming language, VB.NET can also implement polymorphism through inheritance. Today we will introduce to you the specific coding of VB.NET inheritance polymorphism, hoping to bring you some help and improve the efficiency of programming.
Most object-oriented program development systems achieve polymorphism through inheritance. For example, fleas and dogs are inherited from animals. In order to highlight the characteristics of the movement of each kind of animal, each particular kind of animal should overload the "Move" method of the animal class.
The problem with VB.NET inheritance implementing polymorphism is that users can call "Move" methods in a variety of specific animal classes derived from animals when they do not know which particular animal to deal with.
In the following TestPolymorphism process, VB.NET inherits a code example that implements polymorphism:
MustInherit Public Class Amimal
'basic class
MustOverride Public Sub Bite
(Byval What As Object)
MustOverride Public Sub Move
(ByRef Distance As Double)
End Class
Public Class Flea
Inherits Amimal
Overrides Sub bite (Byval What
As Object)
'Bite something
End Sub
Overrides Sub Move (ByRef
Distance As Double)
Distance=Distance+1
End Sub
End Class
Public Class Dog
Inherits Animal
Overrides Public Sub bite
(Byval What As Object)
'Bite something
End Sub
Overrides Sub Move (ByRef
Distance As Double)
Distance=Distance+100
End Sub
End Class
Sub TestPolymorphism ()
Dim aDog As New Dog ()
Dim aFlea As New Flea ()
UseAnimal (aFlea) 'Pass a flea
Object to UseAnimal procedure
UseAnimal (aDog) 'Pass aDog
Object to UseAnimal procedure
End Sub
Sub UseAnimal (Byval AnAnimal As Animal)
Dim distance As Double=0
'UseAnimal does not care what
Kind of animal it is using
'The Move method of both the
Flea and the Dog are inherited
'from the Animal class and can
Be used interchangeably.
AnAniml.Move (distance)
If distance=1 Then
MessageBox.Show ("The animal moved:
"& CStr (distance) & _
"units,so it must be a Flea."
ElseIf distance > 1 Then
MessageBox.Show ("The animal"
Moved: "& CStr (distance) & _
"units,so it must be a Dog."
End IF
End Sub
On how to carry out VB.NET inheritance to achieve polymorphic applications to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.