SlideShare a Scribd company logo
1 of 11
Download to read offline
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

PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
nhezmainit1
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 

Recently uploaded (20)

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 

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)