SlideShare a Scribd company logo
Example Of Inheritance
(Console Apps)(modified)
•	 Simple Inheritance
•	 Hierarchical Inheritance
•	 Multi-level Inheritance
•	 Hybrid Inheritance
•	 Multiple Inheritance
Surojit
Paul
page2
Simple Inheritance
'Example of Simple Inheritance
'create a phone class
Class Phone
'all phones can make a call
Public Sub CanCall()
Console.WriteLine("Yes, you can call")
End Sub
End Class
'smartphone is a phone but you can do much more
Class SmartPhone : Inherits Phone
'only smart phones are capable of gaming and chating
Public Sub canPlayPUBG()
Console.WriteLine("Yes, you can play PUBG")
End Sub
Public Sub canChat()
Console.WriteLine("Yes, you can chat")
End Sub
End Class
Module Module1
Sub Main()
'create a Phone name 'nokia'
Dim nokia As New Phone
Console.WriteLine("nokia")
nokia.CanCall() 'can only make calls
Console.WriteLine()
'create a SmartPhone name 'OnePlus7'
Dim OnePlus7 As New SmartPhone
Console.WriteLine("OnePlus7")
OnePlus7.CanCall() 'make calls
OnePlus7.canPlayPUBG() 'can play game
OnePlus7.canChat() 'and chat
Console.ReadKey()
End Sub
End Module
page3
Hierarchical Inheritance
'Example Of Hierarchical inheritance
'Create a Tiger class
Class Tiger
Public Sub HowmanyLegs()
'a tiger always has 4 legs no matter what kind of it is.
Console.WriteLine("Legs: 4 Lengs")
End Sub
Public Sub location()
'a tiger need some place to live
'but differ with the kind of tiger
Console.WriteLine("Location Unknown")
End Sub
End Class
Class RoyalBengalTiger : Inherits Tiger
'only royal bengal tiger have visible dark strips
Public Sub hasStripe()
Console.WriteLine("Strip Present")
End Sub
'overloads the location from 'Tiger' Class
Public Overloads Sub location()
Console.WriteLine("Location: Sundarban- West Bengal and Bangla-
desh")
End Sub
End Class
Class SnowLepard : Inherits Tiger
'only snowlepard are white
Public Sub Color()
Console.WriteLine("Almost White")
End Sub
'overloads the location from 'Tiger' Class
Public Overloads Sub location()
Console.WriteLine("location: Tundra, in parts of alaska and Russia")
End Sub
End Class
page4
Module Module1
Sub Main()
'all tigers have two things in common
'1. location
'2. Number of Legs
	 'create a Tiger name 'LostLeg'
'in this case type of tiger is not specified
Dim LostLeg As New Tiger
LostLeg.HowmanyLegs()
LostLeg.location()
Console.WriteLine()
'create a RoyalBengalTiger name 'gavin'
Dim gavin As New RoyalBengalTiger
gavin.HowmanyLegs()
gavin.location()
gavin.hasStripe() 'only a Royal Bengal Tiger
	 'has hasStripe() method
Console.WriteLine()
'create a SnowLepard name 'swift'
Dim swift As New SnowLepard
swift.HowmanyLegs()
swift.location()
swift.Color() ' only a snow lepard has Color() method
Console.ReadKey()
End Sub
End Module
page5
Multi-Level Inheritance
'base Class
Class Drinks
Public Sub isLiqud()
Console.WriteLine("Drink is Liquid")
End Sub
Public Sub isDrinkableByChild()
Console.WriteLine("Unknown")
End Sub
End Class
'inherits Drinks
Class SoftDrink : Inherits Drinks
Public Overloads Sub isDrinkableByChild()
Console.WriteLine("Yes, a child can Consume")
End Sub
Public Sub needSugar()
Console.WriteLine("Sugar ?: Yes, need Sugar")
End Sub
End Class
'inherits SoftDrinks
Class Cola : Inherits SoftDrink
Public Sub isHaveSoda()
Console.WriteLine("Soda ? : yes , have soda")
End Sub
End Class
Module Module1
Sub Main()
Dim LemonJuice As New Drinks
Console.WriteLine("LemonJuice")
LemonJuice.isLiqud()
LemonJuice.isDrinkableByChild()
Console.WriteLine()
Dim AppleJuice As New SoftDrink
Console.WriteLine("AppleJuice")
AppleJuice.isLiqud()
AppleJuice.isDrinkableByChild()
AppleJuice.needSugar()
Console.WriteLine()
Dim Pepsi As New Cola
Console.WriteLine("Pepsi")
Pepsi.isLiqud()
Pepsi.isDrinkableByChild()
Pepsi.needSugar()
Pepsi.isHaveSoda()
page6
Console.ReadKey()
End Sub
End Module
page7
Hybrid Inheritance
'base Class
Class Drinks
Public Sub isLiqud()
Console.WriteLine("Drink is Liquid")
End Sub
Public Sub isDrinkableByChild()
Console.WriteLine("Unknown")
End Sub
End Class
'inherits Drinks
Class SoftDrink : Inherits Drinks
Public Overloads Sub isDrinkableByChild()
Console.WriteLine("Yes, a child can Consume")
End Sub
Public Sub needSugar()
Console.WriteLine("Sugar ?: Yes, need Sugar")
End Sub
End Class
'inherits Drinks
Class HardDrinks : Inherits Drinks
Public Overloads Sub isDrinkableByChild()
Console.WriteLine("No, illegal to Cosume by a child")
End Sub
Public Sub haveAlcohol()
Console.WriteLine("Alcohol ?: Yes, have alcohol")
End Sub
End Class
'inherits SoftDrinks
Class Cola : Inherits SoftDrink
Public Sub isHaveSoda()
Console.WriteLine("Soda ? : yes , have soda")
End Sub
End Class
'inherits HardDrinks
Class Beer : Inherits HardDrinks
Public Sub isBadForHealth()
Console.WriteLine("Bad ?: Yes!, very much.")
End Sub
End Class
page8
Module Module1
Sub Main()
Dim LemonJuice As New Drinks
Console.WriteLine("LemonJuice")
LemonJuice.isLiqud()
LemonJuice.isDrinkableByChild()
Console.WriteLine()
Dim AppleJuice As New SoftDrink
Console.WriteLine("AppleJuice")
AppleJuice.isLiqud()
AppleJuice.isDrinkableByChild()
AppleJuice.needSugar()
Console.WriteLine()
Dim Pepsi As New Cola
Console.WriteLine("Pepsi")
Pepsi.isLiqud()
Pepsi.isDrinkableByChild()
Pepsi.needSugar()
Pepsi.isHaveSoda()
Console.WriteLine()
Dim AlcoholicDrink As New HardDrinks
Console.WriteLine("AlcoholicDrink")
AlcoholicDrink.isLiqud()
AlcoholicDrink.isDrinkableByChild()
AlcoholicDrink.haveAlcohol()
Console.WriteLine()
Dim BeerCocktail As New Beer
Console.WriteLine("BeerCocktail")
BeerCocktail.isLiqud()
BeerCocktail.isDrinkableByChild()
BeerCocktail.haveAlcohol()
BeerCocktail.isBadForHealth()
Console.ReadKey()
End Sub
End Module
page9
Multiple-Inheritance 1 (Interface)
Interface AnimalCharacter
Sub howmanyLegs()
Sub talk()
End Interface
Class Animal
Public Sub canWalk()
Console.WriteLine("Yes, This animal Can Walk")
End Sub
End Class
Class dog : Inherits Animal : Implements AnimalCharacter
Public Sub howmanyLegs() Implements AnimalCharacter.howmanyLegs
Console.WriteLine("Dogs have 4 legs")
End Sub
Public Sub talk() Implements AnimalCharacter.talk
Console.WriteLine("Make Sound:- bow bow")
End Sub
End Class
Class human : Inherits Animal : Implements AnimalCharacter
Public Sub howmanyLegs() Implements AnimalCharacter.howmanyLegs
Console.WriteLine("Human have 2 legs")
End Sub
Public Sub talk() Implements AnimalCharacter.talk
Console.WriteLine("Make Sound:- Hello, i am a human")
End Sub
End Class
Module Module1
Sub Main()
Dim barky As New dog
Console.WriteLine("Barky")
barky.howmanyLegs() 'from interface so value can differ (4 legs)
barky.talk() 'from interface so value can differ
barky.canWalk() ' from base class so value will be same
Console.WriteLine()
Dim jack As New human
Console.WriteLine("Jack")
jack.howmanyLegs() 'from interface so value can differ (2 legs)
jack.talk() 'from interface so value can differ
page10
jack.canWalk() ' from base class so value will be same
Console.ReadKey()
End Sub
End Module
page11
Interface interface1
Sub add() 'to add two number
End Interface
Interface interface2
Sub multiply() 'to multiply two number
End Interface
'this class will share methods of both interfaces
Public Class MathClass : Implements interface1, interface2
Private number1, number2 As Integer
Public Sub New(ByVal n1 As Integer, ByVal n2 As Integer) 'this called a Constructer
number1 = n1
number2 = n2
End Sub
Public Sub add() Implements interface1.add 'from interface1
Console.WriteLine("Add: " & number1 & "+" & number2 & " = " & number2 + number1)
End Sub
Public Sub multiply() Implements interface2.multiply 'from interface2
Console.WriteLine("Multiply: " & number1 & "*" & number2 & " = " & number2 * number1)
End Sub
End Class
Module Module1
Sub Main()
' change this two number to chnage the output
Dim equ1 As New MathClass(12, 2)
equ1.add() 'from interface1
equ1.multiply() 'from interface2
Console.ReadKey()
End Sub
End Module
Multiple-Inheritance 2 (2 Interface)

More Related Content

Similar to New inheritance

A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
旻琦 潘
 

Similar to New inheritance (20)

The Ring programming language version 1.5.4 book - Part 47 of 185
The Ring programming language version 1.5.4 book - Part 47 of 185The Ring programming language version 1.5.4 book - Part 47 of 185
The Ring programming language version 1.5.4 book - Part 47 of 185
 
Ruby
RubyRuby
Ruby
 
Why Every Tester Should Learn Ruby
Why Every Tester Should Learn RubyWhy Every Tester Should Learn Ruby
Why Every Tester Should Learn Ruby
 
Kotlin for Android Developers - 1
Kotlin for Android Developers - 1Kotlin for Android Developers - 1
Kotlin for Android Developers - 1
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
KMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftKMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and Swift
 
Модерни езици за програмиране за JVM (2011)
Модерни езици за програмиране за JVM (2011)Модерни езици за програмиране за JVM (2011)
Модерни езици за програмиране за JVM (2011)
 
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
 
NUS iOS Swift Talk
NUS iOS Swift TalkNUS iOS Swift Talk
NUS iOS Swift Talk
 
The Ring programming language version 1.5.4 book - Part 15 of 185
The Ring programming language version 1.5.4 book - Part 15 of 185The Ring programming language version 1.5.4 book - Part 15 of 185
The Ring programming language version 1.5.4 book - Part 15 of 185
 
The Ring programming language version 1.5.2 book - Part 47 of 181
The Ring programming language version 1.5.2 book - Part 47 of 181The Ring programming language version 1.5.2 book - Part 47 of 181
The Ring programming language version 1.5.2 book - Part 47 of 181
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
 
Solution manual of shell programming assignment 2
Solution manual of shell programming assignment 2Solution manual of shell programming assignment 2
Solution manual of shell programming assignment 2
 
"Elixir of Life" - Dev In Santos
"Elixir of Life" - Dev In Santos"Elixir of Life" - Dev In Santos
"Elixir of Life" - Dev In Santos
 
Building a Tagless Final DSL for WebGL
Building a Tagless Final DSL for WebGLBuilding a Tagless Final DSL for WebGL
Building a Tagless Final DSL for WebGL
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
Language supports it
Language supports itLanguage supports it
Language supports it
 
JRuby e DSL
JRuby e DSLJRuby e DSL
JRuby e DSL
 

Recently uploaded

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 

Recently uploaded (20)

1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 

New inheritance

  • 1. Example Of Inheritance (Console Apps)(modified) • Simple Inheritance • Hierarchical Inheritance • Multi-level Inheritance • Hybrid Inheritance • Multiple Inheritance Surojit Paul
  • 2. page2 Simple Inheritance 'Example of Simple Inheritance 'create a phone class Class Phone 'all phones can make a call Public Sub CanCall() Console.WriteLine("Yes, you can call") End Sub End Class 'smartphone is a phone but you can do much more Class SmartPhone : Inherits Phone 'only smart phones are capable of gaming and chating Public Sub canPlayPUBG() Console.WriteLine("Yes, you can play PUBG") End Sub Public Sub canChat() Console.WriteLine("Yes, you can chat") End Sub End Class Module Module1 Sub Main() 'create a Phone name 'nokia' Dim nokia As New Phone Console.WriteLine("nokia") nokia.CanCall() 'can only make calls Console.WriteLine() 'create a SmartPhone name 'OnePlus7' Dim OnePlus7 As New SmartPhone Console.WriteLine("OnePlus7") OnePlus7.CanCall() 'make calls OnePlus7.canPlayPUBG() 'can play game OnePlus7.canChat() 'and chat Console.ReadKey() End Sub End Module
  • 3. page3 Hierarchical Inheritance 'Example Of Hierarchical inheritance 'Create a Tiger class Class Tiger Public Sub HowmanyLegs() 'a tiger always has 4 legs no matter what kind of it is. Console.WriteLine("Legs: 4 Lengs") End Sub Public Sub location() 'a tiger need some place to live 'but differ with the kind of tiger Console.WriteLine("Location Unknown") End Sub End Class Class RoyalBengalTiger : Inherits Tiger 'only royal bengal tiger have visible dark strips Public Sub hasStripe() Console.WriteLine("Strip Present") End Sub 'overloads the location from 'Tiger' Class Public Overloads Sub location() Console.WriteLine("Location: Sundarban- West Bengal and Bangla- desh") End Sub End Class Class SnowLepard : Inherits Tiger 'only snowlepard are white Public Sub Color() Console.WriteLine("Almost White") End Sub 'overloads the location from 'Tiger' Class Public Overloads Sub location() Console.WriteLine("location: Tundra, in parts of alaska and Russia") End Sub End Class
  • 4. page4 Module Module1 Sub Main() 'all tigers have two things in common '1. location '2. Number of Legs 'create a Tiger name 'LostLeg' 'in this case type of tiger is not specified Dim LostLeg As New Tiger LostLeg.HowmanyLegs() LostLeg.location() Console.WriteLine() 'create a RoyalBengalTiger name 'gavin' Dim gavin As New RoyalBengalTiger gavin.HowmanyLegs() gavin.location() gavin.hasStripe() 'only a Royal Bengal Tiger 'has hasStripe() method Console.WriteLine() 'create a SnowLepard name 'swift' Dim swift As New SnowLepard swift.HowmanyLegs() swift.location() swift.Color() ' only a snow lepard has Color() method Console.ReadKey() End Sub End Module
  • 5. page5 Multi-Level Inheritance 'base Class Class Drinks Public Sub isLiqud() Console.WriteLine("Drink is Liquid") End Sub Public Sub isDrinkableByChild() Console.WriteLine("Unknown") End Sub End Class 'inherits Drinks Class SoftDrink : Inherits Drinks Public Overloads Sub isDrinkableByChild() Console.WriteLine("Yes, a child can Consume") End Sub Public Sub needSugar() Console.WriteLine("Sugar ?: Yes, need Sugar") End Sub End Class 'inherits SoftDrinks Class Cola : Inherits SoftDrink Public Sub isHaveSoda() Console.WriteLine("Soda ? : yes , have soda") End Sub End Class Module Module1 Sub Main() Dim LemonJuice As New Drinks Console.WriteLine("LemonJuice") LemonJuice.isLiqud() LemonJuice.isDrinkableByChild() Console.WriteLine() Dim AppleJuice As New SoftDrink Console.WriteLine("AppleJuice") AppleJuice.isLiqud() AppleJuice.isDrinkableByChild() AppleJuice.needSugar() Console.WriteLine() Dim Pepsi As New Cola Console.WriteLine("Pepsi") Pepsi.isLiqud() Pepsi.isDrinkableByChild() Pepsi.needSugar() Pepsi.isHaveSoda()
  • 7. page7 Hybrid Inheritance 'base Class Class Drinks Public Sub isLiqud() Console.WriteLine("Drink is Liquid") End Sub Public Sub isDrinkableByChild() Console.WriteLine("Unknown") End Sub End Class 'inherits Drinks Class SoftDrink : Inherits Drinks Public Overloads Sub isDrinkableByChild() Console.WriteLine("Yes, a child can Consume") End Sub Public Sub needSugar() Console.WriteLine("Sugar ?: Yes, need Sugar") End Sub End Class 'inherits Drinks Class HardDrinks : Inherits Drinks Public Overloads Sub isDrinkableByChild() Console.WriteLine("No, illegal to Cosume by a child") End Sub Public Sub haveAlcohol() Console.WriteLine("Alcohol ?: Yes, have alcohol") End Sub End Class 'inherits SoftDrinks Class Cola : Inherits SoftDrink Public Sub isHaveSoda() Console.WriteLine("Soda ? : yes , have soda") End Sub End Class 'inherits HardDrinks Class Beer : Inherits HardDrinks Public Sub isBadForHealth() Console.WriteLine("Bad ?: Yes!, very much.") End Sub End Class
  • 8. page8 Module Module1 Sub Main() Dim LemonJuice As New Drinks Console.WriteLine("LemonJuice") LemonJuice.isLiqud() LemonJuice.isDrinkableByChild() Console.WriteLine() Dim AppleJuice As New SoftDrink Console.WriteLine("AppleJuice") AppleJuice.isLiqud() AppleJuice.isDrinkableByChild() AppleJuice.needSugar() Console.WriteLine() Dim Pepsi As New Cola Console.WriteLine("Pepsi") Pepsi.isLiqud() Pepsi.isDrinkableByChild() Pepsi.needSugar() Pepsi.isHaveSoda() Console.WriteLine() Dim AlcoholicDrink As New HardDrinks Console.WriteLine("AlcoholicDrink") AlcoholicDrink.isLiqud() AlcoholicDrink.isDrinkableByChild() AlcoholicDrink.haveAlcohol() Console.WriteLine() Dim BeerCocktail As New Beer Console.WriteLine("BeerCocktail") BeerCocktail.isLiqud() BeerCocktail.isDrinkableByChild() BeerCocktail.haveAlcohol() BeerCocktail.isBadForHealth() Console.ReadKey() End Sub End Module
  • 9. page9 Multiple-Inheritance 1 (Interface) Interface AnimalCharacter Sub howmanyLegs() Sub talk() End Interface Class Animal Public Sub canWalk() Console.WriteLine("Yes, This animal Can Walk") End Sub End Class Class dog : Inherits Animal : Implements AnimalCharacter Public Sub howmanyLegs() Implements AnimalCharacter.howmanyLegs Console.WriteLine("Dogs have 4 legs") End Sub Public Sub talk() Implements AnimalCharacter.talk Console.WriteLine("Make Sound:- bow bow") End Sub End Class Class human : Inherits Animal : Implements AnimalCharacter Public Sub howmanyLegs() Implements AnimalCharacter.howmanyLegs Console.WriteLine("Human have 2 legs") End Sub Public Sub talk() Implements AnimalCharacter.talk Console.WriteLine("Make Sound:- Hello, i am a human") End Sub End Class Module Module1 Sub Main() Dim barky As New dog Console.WriteLine("Barky") barky.howmanyLegs() 'from interface so value can differ (4 legs) barky.talk() 'from interface so value can differ barky.canWalk() ' from base class so value will be same Console.WriteLine() Dim jack As New human Console.WriteLine("Jack") jack.howmanyLegs() 'from interface so value can differ (2 legs) jack.talk() 'from interface so value can differ
  • 10. page10 jack.canWalk() ' from base class so value will be same Console.ReadKey() End Sub End Module
  • 11. page11 Interface interface1 Sub add() 'to add two number End Interface Interface interface2 Sub multiply() 'to multiply two number End Interface 'this class will share methods of both interfaces Public Class MathClass : Implements interface1, interface2 Private number1, number2 As Integer Public Sub New(ByVal n1 As Integer, ByVal n2 As Integer) 'this called a Constructer number1 = n1 number2 = n2 End Sub Public Sub add() Implements interface1.add 'from interface1 Console.WriteLine("Add: " & number1 & "+" & number2 & " = " & number2 + number1) End Sub Public Sub multiply() Implements interface2.multiply 'from interface2 Console.WriteLine("Multiply: " & number1 & "*" & number2 & " = " & number2 * number1) End Sub End Class Module Module1 Sub Main() ' change this two number to chnage the output Dim equ1 As New MathClass(12, 2) equ1.add() 'from interface1 equ1.multiply() 'from interface2 Console.ReadKey() End Sub End Module Multiple-Inheritance 2 (2 Interface)