日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
VB.NET繼承實(shí)現(xiàn)多態(tài)應(yīng)用方法介紹

最為一款面向?qū)ο蟮木幊陶Z(yǔ)言,VB.NET同樣也可以通過(guò)繼承進(jìn)行多態(tài)的實(shí)現(xiàn)。我們今天就為大家介紹一下有關(guān)VB.NET繼承實(shí)現(xiàn)多態(tài)的具體代碼編寫,希望能給大家?guī)?lái)一些幫助,提高編程效率。

大部分面向?qū)ο蟮某绦蜷_發(fā)系統(tǒng)都是通過(guò)繼承來(lái)實(shí)現(xiàn)多態(tài)。比如說(shuō)跳蚤類和狗類都是從動(dòng)物類繼承過(guò)來(lái)的。為了突出每一種動(dòng)物走動(dòng)的特點(diǎn),則每一種特定動(dòng)物類都要重載動(dòng)物類的"Move"方法。

VB.NET繼承實(shí)現(xiàn)多態(tài)的問(wèn)題是因?yàn)橛脩艨梢孕枰谶€不知道是要對(duì)哪種特定動(dòng)物進(jìn)行處理的時(shí)候,就要調(diào)用多種從動(dòng)物類中派生出來(lái)的特定的動(dòng)物類中的"Move"方法。

在下面的這個(gè)TestPolymorphism過(guò)程中,VB.NET繼承實(shí)現(xiàn)多態(tài)的代碼示例:

 
 
 
  1. MustInherit Public Class Amimal 
    '基本類  
  2. MustOverride Public Sub Bite
    (Byval What As Object)  
  3. MustOverride Public Sub Move
    (ByRef Distance As Double)  
  4. End Class  
  5. Public Class Flea  
  6. Inherits Amimal  
  7. Overrides Sub bite(Byval What 
    As Object)  
  8. 'Bite something  
  9. End Sub  
  10. Overrides Sub Move(ByRef 
    Distance As Double)  
  11. distance=Distance+1  
  12. End Sub  
  13. End Class  
  14. Public Class Dog  
  15. Inherits Animal  
  16. Overrides Public Sub bite
    (Byval What As Object)  
  17. 'Bite something  
  18. End Sub  
  19. Overrides Sub Move(ByRef 
    Distance As Double)  
  20. distance=Distance+100  
  21. End Sub  
  22. End Class  
  23. Sub TestPolymorphism()  
  24. Dim aDog As New Dog()  
  25. Dim aFlea As New Flea()  
  26. UseAnimal(aFlea) 'Pass a flea 
    object to UseAnimal procedure  
  27. UseAnimal(aDog) 'Pass a Dog 
    object to UseAnimal procedure  
  28. End Sub  
  29. Sub UseAnimal(Byval AnAnimal As Animal)  
  30. Dim distance As Double=0 
  31. 'UseAnimal does not care what 
    kind of animal it is using  
  32. 'The Move method of both the 
    Flea and the Dog are inherited  
  33. 'from the Animal class and can 
    be used interchangeably.  
  34. AnAniml.Move(distance)  
  35. If distance=1 Then  
  36. MessageBox.Show("The animal moved:
    "&CStr(distance)&_  
  37. "units,so it must be a Flea.")  
  38. ElseIf distance>1 Then  
  39. MessageBox.Show("The animal 
    moved:"&CStr(distance)&_  
  40. "units,so it must be a Dog.")  
  41. End IF  
  42. End Sub 

VB.NET繼承實(shí)現(xiàn)多態(tài)的相關(guān)代碼編寫就為大家介紹到這里。

【編輯推薦】

  1. VB.NET命名空間各種類型簡(jiǎn)要概述
  2. VB.NET繼承重要作用體現(xiàn)
  3. VB.NET抽象類應(yīng)用方式剖析
  4. VB.NET顯示系統(tǒng)信息正確實(shí)現(xiàn)方法介紹
  5. VB.NET變量范圍規(guī)則解析

新聞標(biāo)題:VB.NET繼承實(shí)現(xiàn)多態(tài)應(yīng)用方法介紹
標(biāo)題來(lái)源:http://www.dlmjj.cn/article/dhpsiid.html