請問vb.net的繼承

看板Programming作者時間18年前 (2007/10/23 07:32), 編輯推噓1(101)
留言2則, 1人參與, 最新討論串1/1
請問以下的繼承程式,如果祖父有一百萬 大兒子得到50萬,二兒子得到剩下的40%,也就是20萬 而大兒子的兒子(也就是孫子)他可以得到大兒子的一半,也就是25萬 請問我該如何設計呢? 因為我原本的設計,孫子會得到6萬... 謝謝! 附上語法如下: Public Class Father Public Shared Money As Long = 1000000 End Class Public Class Son Inherits Father '3 宣告必須放在最前面 Public money2 As Long Public Sub New() MyClass.money2 = MyBase.Money * 0.4 MyBase.Money -= MyClass.money2 MsgBox("son跑完後 father剩下" & MyBase.Money) End Sub End Class Public Class Son2 Inherits Father Public money2 As Long Public Sub New() MyClass.money2 = MyBase.Money * 0.5 MyBase.Money -= MyClass.money2 MsgBox("son2跑完後 father剩下" & MyBase.Money) End Sub End Class Public Class GrandSon '繼承son 而非 father Inherits Son Public money3 As Long Public Sub New() MyClass.money3 = MyBase.money2 * 0.5 MyBase.Money -= MyClass.money3 MsgBox("grandson跑完後 father剩下" & MyBase.Money) End Sub End Class Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button1.Click Dim John As New Son MsgBox("我有" & John.money2 & " 元!!") End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button2.Click Dim jason As New Son2 MsgBox("我有" & jason.money2 & " 元!!") End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button3.Click Dim Jimy As New GrandSon MsgBox("我有" & Jimy.money3 & " 元!!") End Sub End Class -- ┌─────KKCITY─────┐ KKCITY 市民小密技 -文章標題上- bbs.kkcity.com.tw Ctrl+y 可設定單篇文章加密 └──From:218.169.107.194 ──┘ Shift+y 可設定單篇文章密碼 --

10/23 13:43, , 1F
我覺得這樣寫好像違背 inheritence 的
10/23 13:43, 1F

10/23 13:43, , 2F
本意...
10/23 13:43, 2F
文章代碼(AID): #177JBu00 (Programming)
文章代碼(AID): #177JBu00 (Programming)