vb.net 实现多态
2024-09-01 13:33:50
1. 新建一个module,设置public 其他类才可以调用
Public Module Module2
Public Interface MyInterface
Property stuName As String
Function GetScore(ByVal x As Single) As Single
End Interface Public Class StuInfo
Implements MyInterface
Private studentScore As Single
Private studentName As String
Public Property Score() As Single
Get
Return studentScore
End Get
Set(ByVal value As Single)
studentScore = value
End Set
End Property
Public Function GetScore(ByVal x As Single) As Single Implements MyInterface.GetScore
Return x * 0.8
End Function Public Property StuName() As String Implements MyInterface.stuName
Get
Return studentName
End Get
Set(ByVal value As String)
studentName = value
End Set
End Property
End Class Public Class StuMessage
Implements MyInterface
Private studentName As String
Private stuScore As Single
Public Property Score() As Single
Get
Return stuScore
End Get
Set(ByVal value As Single)
stuScore = value
End Set
End Property
Public Function GetScore(ByVal x As Single) As Single Implements MyInterface.GetScore
Return x * 0.8
End Function Public Property StuName() As String Implements MyInterface.stuName
Get
Return studentName
End Get
Set(ByVal value As String)
studentName = value
End Set
End Property End Class End Module
2. 测试页面:
Public Class TestClassForm
Public Sub ShowScore(ByVal obj As MyInterface, ByVal s As String, ByVal score As Single)
MsgBox(s & "成绩为:" & obj.GetScore(score) & "")
End Sub
Private Sub TestClassForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim obj1 As New StuInfo()
Dim obj2 As New StuMessage()
ShowScore(obj1, "期中", )
ShowScore(obj2, "期末", )
End Sub
End Class
最新文章
- [Web API] Web API 2 深入系列(4) Action的选择
- Loadrunner之API测试
- winform建立非矩形窗体
- jQuery document window load ready 区别详解
- 11.Warning (332060): Node: pi_fck3p was determined to be a clock but was found without an associated clock assignment.
- Web网站压力测试工具
- c#委托把方法当成参数
- WPF textbox 圆角制作
- 网页嵌入百度地图和使用百度地图api自定义地图的详细步骤
- 递归——CPS(一)
- Ubuntu下php网站运行环境搭建
- Serv-U FTP版本控制服务器 - 目录规范
- Expected MultipartHttpServletRequest: is a MultipartResolver configured解决方案
- Spring MVC的DispatcherServlet
- nginx实现https网站设置
- Nginx (LNMP+https)
- request.getParameter(“xxx”)的参数的取值
- hdu 1013 过山车 匈牙利算法(代码+详细注释)
- Thinkphp分页类使用
- vi规范
热门文章
- php多版本使用composer
- ASP.NET + MVC5 入门完整教程七 -—-- MVC基本工具(下)
- css各类选择器类型和用法
- 【转】Java8 Stream 流详解
- Android开发实战——记账本(2)
- webpack4.41.0配置四(热替换)
- VS调试工具
- KM算法模板 hdu 2255
- Bug搬运工-Forerunner CRC error on 54SG/53SG3 triggers watchdog timeout crash
- [远古回忆]发现了以前的一些wow截图 这里也备份一下