SlideShare a Scribd company logo
1 of 10
Inheritance
BCA -501
2
What is inheritance?
 Inheritance can be defined as the feature of the programming language that offers an
opportunity to make the use of functions that are already defined in a base class.
 In Inheritance, the base class is the class which passes its functionality to other class. It
is also called the parent class sometimes.
 The class that inherits the base class is called derived class and sometimes called child
class as well.
 As the word inheritance itself demonstrates, it facilitates the passing of values or
functions to some other classes. In VB.Net we can inherit more than one class to the
derived class simultaneously.
3
What is inheritance?
 The purpose of inheritance is to make reduce the size of code and avoid defining the
same function multiple times.
 Inheritance may be defined as the property of programming language that implements
the mechanism of reusing the already defined functionality.
 It is very useful when it comes to developing an application with efficient code.
 There is no need to write the same function over and over.
 It could be used several times based on the requirement.
4
Advantages of Inheritance
The feature of inheritance is very beneficial in programming. It actually helps a lot while
writing complex programs as the feature of passing the functionality mitigates the complex
looks of the code. Below are some of its common Advantages
 Reduces ambiguity – The code once is written could be used several times. Hence it
eliminates the duplicates and makes the code unambiguous.
 Reusability – It follows the rule of creating once and use multiple times. Once any
function is defined, we can use that function n number of times based on our
requirement.
 Eliminate Coding Complexity – The code has to be written precisely in order to follow
proper documentation and make it easy for other developers to understand the code. It
could be done with the help of Inheritance.
 Enhances program efficiency – The program that makes the use of inheritance are very
efficient as there are a few numbers of lines as compared to the same program which
was developed without inheritance.
5
Syntax for implementing inheritance
[access specifier] Class [Base class name] Statement 1
Statement 2
..
Statement n
End Class
Class [Derived class name] Inherits [Base class name] Statement 1
Statement 2
..
Statement n
End Class
Here, the based classed has to be defined first. Then by making the use of the “Inherits”
keyword, we can implement inheritance in the program. So basically we need at least two
classes to take leverage of inheritance. Once the class has to be the base class while
others will be the derived class.
6
Example for implementing inheritance
Module module1
Class x
Public name As String
Public roll As Integer
Public Sub get_data()
Console.WriteLine("Enter Name: ")
name = Console.ReadLine()
Console.WriteLine("Enter Roll ")
roll = Console.ReadLine()
End Sub
End Class
Class y : Inherits x
Public Sub display_data()
Console.WriteLine("You have entered following details:")
Console.WriteLine("Name: {0}", name)
Console.WriteLine("Roll: {0}", roll)
End Sub
End Class
Sub main()
Dim obj As New y()
obj.get_data()
obj.display_data()
Console.ReadKey()
End Sub
End Module
7
Inheriting Constructor and Destructors
Module module1
Class x
Public Sub New()
Console.WriteLine("Constructor of Base Class")
End Sub
Protected Overrides Sub Finalize()
Console.WriteLine("Destructor of Base class called")
End Sub
End Class
Class y : Inherits x
End Class
Sub main()
Dim obj As New x()
Dim obj1 As New y()
Console.ReadKey()
End Sub
End Module
Constructors and Destructor are, by default, inherited by derived classes.
Module module1
Class x
Public Sub New()
Console.WriteLine("Constructor of Base Class")
End Sub
End Class
Class y
Inherits x
'End Class
Sub main()
Dim obj As New x()
Dim obj1 As New y()
Console.ReadKey()
End Sub
End Module
8
Abstract and Final Class
 An abstract class is a class that cannot be instantiated.
 An abstract class cannot be used to create objects.
 It is generally used as a template to derive other classes.
 An abstract class typically has abstract methods which are only method declarations
 Without any implementation.
 A final class is a class that cannot be used as a base class. This means a final class
cannot be used to derive classes or cannot be inherited.
 A class cannot be both abstract as well as final.
 In VB.NET all classes are inheritable. The MustInherit keyword makes the base class an
abstract class.
 Final Classes in VB.NET are marked with NotInheritable Keyword. They cannot have
derived classes but can be used to create objects.
9
Example of Abstract Class
Module module1
MustInherit Class Absbase
Public Sub test()
Console.WriteLine("Abstract Base Class")
End Sub
MustOverride Sub anothertest()
End Class
Class child
Inherits Absbase
Public Overrides Sub anothertest()
Console.WriteLine("Implementing abstract methods")
End Sub
End Class
Sub main()
Dim obj As New child()
obj.test()
obj.anothertest()
Console.ReadKey()
End Sub
End Module
10
Example of Final Class
Module module1
NotInheritable Class A
Public Sub test()
Console.WriteLine("Parameter not passes")
End Sub
Public Sub test(x As Integer)
Console.WriteLine("Value :", x)
End Sub
End Class
Sub main()
Dim obj As New A()
obj.test()
obj.test(100)
Console.ReadKey()
End Sub
End Module

More Related Content

What's hot (20)

Class and object
Class and objectClass and object
Class and object
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.net
 
C# interview
C# interviewC# interview
C# interview
 
Inheritance
InheritanceInheritance
Inheritance
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Java basic concept
Java basic conceptJava basic concept
Java basic concept
 
Inheritance
InheritanceInheritance
Inheritance
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01
 
Structure in c#
Structure in c#Structure in c#
Structure in c#
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Chapter 8 - Exceptions and Assertions Edit summary
Chapter 8 - Exceptions and Assertions  Edit summaryChapter 8 - Exceptions and Assertions  Edit summary
Chapter 8 - Exceptions and Assertions Edit summary
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 

Similar to Inheritance

Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesDurgesh Singh
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)Jay Patel
 
Mit4021 c# and .net
Mit4021   c# and .netMit4021   c# and .net
Mit4021 c# and .netsmumbahelp
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using ReflectionGanesh Samarthyam
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.Questpond
 
C#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersC#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersSanjaya Prakash Pradhan
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010Rich Helton
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language Hitesh-Java
 
Inheritance in java.ppt
Inheritance in java.pptInheritance in java.ppt
Inheritance in java.pptSeethaDinesh
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++Amresh Raj
 
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScriptLotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScriptBill Buchan
 
MC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall sessionMC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall sessionNarinder Kumar
 
Automation Testing - Part 2 (Things to know in JAVA) - SLT
Automation Testing - Part 2 (Things to know in JAVA) - SLTAutomation Testing - Part 2 (Things to know in JAVA) - SLT
Automation Testing - Part 2 (Things to know in JAVA) - SLTAnkit Prajapati
 
Automation Testing - Part 2 (Things to know in JAVA) - SLT
Automation Testing - Part 2 (Things to know in JAVA) - SLTAutomation Testing - Part 2 (Things to know in JAVA) - SLT
Automation Testing - Part 2 (Things to know in JAVA) - SLTAnkit Prajapati
 

Similar to Inheritance (20)

Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modules
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Mit4021 c# and .net
Mit4021   c# and .netMit4021   c# and .net
Mit4021 c# and .net
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
 
Csci360 20 (1)
Csci360 20 (1)Csci360 20 (1)
Csci360 20 (1)
 
Csci360 20
Csci360 20Csci360 20
Csci360 20
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
 
Ganesh groups
Ganesh groupsGanesh groups
Ganesh groups
 
C#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersC#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developers
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
 
Java_presesntation.ppt
Java_presesntation.pptJava_presesntation.ppt
Java_presesntation.ppt
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
Inheritance in java.ppt
Inheritance in java.pptInheritance in java.ppt
Inheritance in java.ppt
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
 
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScriptLotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
 
MC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall sessionMC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall session
 
Java notes
Java notesJava notes
Java notes
 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
 
Automation Testing - Part 2 (Things to know in JAVA) - SLT
Automation Testing - Part 2 (Things to know in JAVA) - SLTAutomation Testing - Part 2 (Things to know in JAVA) - SLT
Automation Testing - Part 2 (Things to know in JAVA) - SLT
 
Automation Testing - Part 2 (Things to know in JAVA) - SLT
Automation Testing - Part 2 (Things to know in JAVA) - SLTAutomation Testing - Part 2 (Things to know in JAVA) - SLT
Automation Testing - Part 2 (Things to know in JAVA) - SLT
 

More from Jaya Kumari

Python data type
Python data typePython data type
Python data typeJaya Kumari
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonJaya Kumari
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by pythonJaya Kumari
 
Decision statements
Decision statementsDecision statements
Decision statementsJaya Kumari
 
Loop control statements
Loop control statementsLoop control statements
Loop control statementsJaya Kumari
 
Looping statements
Looping statementsLooping statements
Looping statementsJaya Kumari
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.netJaya Kumari
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.netJaya Kumari
 
Frame class library and namespace
Frame class library and namespaceFrame class library and namespace
Frame class library and namespaceJaya Kumari
 
Introduction to .net
Introduction to .net Introduction to .net
Introduction to .net Jaya Kumari
 
Java script Basic
Java script BasicJava script Basic
Java script BasicJaya Kumari
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script AdvanceJaya Kumari
 

More from Jaya Kumari (17)

Python data type
Python data typePython data type
Python data type
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by python
 
Overloading
OverloadingOverloading
Overloading
 
Decision statements
Decision statementsDecision statements
Decision statements
 
Loop control statements
Loop control statementsLoop control statements
Loop control statements
 
Looping statements
Looping statementsLooping statements
Looping statements
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.net
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.net
 
Frame class library and namespace
Frame class library and namespaceFrame class library and namespace
Frame class library and namespace
 
Introduction to .net
Introduction to .net Introduction to .net
Introduction to .net
 
Jsp basic
Jsp basicJsp basic
Jsp basic
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
 
Sgml and xml
Sgml and xmlSgml and xml
Sgml and xml
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script Advance
 
Html form
Html formHtml form
Html form
 
Html Concept
Html ConceptHtml Concept
Html Concept
 

Recently uploaded

Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Recently uploaded (20)

Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

Inheritance

  • 2. 2 What is inheritance?  Inheritance can be defined as the feature of the programming language that offers an opportunity to make the use of functions that are already defined in a base class.  In Inheritance, the base class is the class which passes its functionality to other class. It is also called the parent class sometimes.  The class that inherits the base class is called derived class and sometimes called child class as well.  As the word inheritance itself demonstrates, it facilitates the passing of values or functions to some other classes. In VB.Net we can inherit more than one class to the derived class simultaneously.
  • 3. 3 What is inheritance?  The purpose of inheritance is to make reduce the size of code and avoid defining the same function multiple times.  Inheritance may be defined as the property of programming language that implements the mechanism of reusing the already defined functionality.  It is very useful when it comes to developing an application with efficient code.  There is no need to write the same function over and over.  It could be used several times based on the requirement.
  • 4. 4 Advantages of Inheritance The feature of inheritance is very beneficial in programming. It actually helps a lot while writing complex programs as the feature of passing the functionality mitigates the complex looks of the code. Below are some of its common Advantages  Reduces ambiguity – The code once is written could be used several times. Hence it eliminates the duplicates and makes the code unambiguous.  Reusability – It follows the rule of creating once and use multiple times. Once any function is defined, we can use that function n number of times based on our requirement.  Eliminate Coding Complexity – The code has to be written precisely in order to follow proper documentation and make it easy for other developers to understand the code. It could be done with the help of Inheritance.  Enhances program efficiency – The program that makes the use of inheritance are very efficient as there are a few numbers of lines as compared to the same program which was developed without inheritance.
  • 5. 5 Syntax for implementing inheritance [access specifier] Class [Base class name] Statement 1 Statement 2 .. Statement n End Class Class [Derived class name] Inherits [Base class name] Statement 1 Statement 2 .. Statement n End Class Here, the based classed has to be defined first. Then by making the use of the “Inherits” keyword, we can implement inheritance in the program. So basically we need at least two classes to take leverage of inheritance. Once the class has to be the base class while others will be the derived class.
  • 6. 6 Example for implementing inheritance Module module1 Class x Public name As String Public roll As Integer Public Sub get_data() Console.WriteLine("Enter Name: ") name = Console.ReadLine() Console.WriteLine("Enter Roll ") roll = Console.ReadLine() End Sub End Class Class y : Inherits x Public Sub display_data() Console.WriteLine("You have entered following details:") Console.WriteLine("Name: {0}", name) Console.WriteLine("Roll: {0}", roll) End Sub End Class Sub main() Dim obj As New y() obj.get_data() obj.display_data() Console.ReadKey() End Sub End Module
  • 7. 7 Inheriting Constructor and Destructors Module module1 Class x Public Sub New() Console.WriteLine("Constructor of Base Class") End Sub Protected Overrides Sub Finalize() Console.WriteLine("Destructor of Base class called") End Sub End Class Class y : Inherits x End Class Sub main() Dim obj As New x() Dim obj1 As New y() Console.ReadKey() End Sub End Module Constructors and Destructor are, by default, inherited by derived classes. Module module1 Class x Public Sub New() Console.WriteLine("Constructor of Base Class") End Sub End Class Class y Inherits x 'End Class Sub main() Dim obj As New x() Dim obj1 As New y() Console.ReadKey() End Sub End Module
  • 8. 8 Abstract and Final Class  An abstract class is a class that cannot be instantiated.  An abstract class cannot be used to create objects.  It is generally used as a template to derive other classes.  An abstract class typically has abstract methods which are only method declarations  Without any implementation.  A final class is a class that cannot be used as a base class. This means a final class cannot be used to derive classes or cannot be inherited.  A class cannot be both abstract as well as final.  In VB.NET all classes are inheritable. The MustInherit keyword makes the base class an abstract class.  Final Classes in VB.NET are marked with NotInheritable Keyword. They cannot have derived classes but can be used to create objects.
  • 9. 9 Example of Abstract Class Module module1 MustInherit Class Absbase Public Sub test() Console.WriteLine("Abstract Base Class") End Sub MustOverride Sub anothertest() End Class Class child Inherits Absbase Public Overrides Sub anothertest() Console.WriteLine("Implementing abstract methods") End Sub End Class Sub main() Dim obj As New child() obj.test() obj.anothertest() Console.ReadKey() End Sub End Module
  • 10. 10 Example of Final Class Module module1 NotInheritable Class A Public Sub test() Console.WriteLine("Parameter not passes") End Sub Public Sub test(x As Integer) Console.WriteLine("Value :", x) End Sub End Class Sub main() Dim obj As New A() obj.test() obj.test(100) Console.ReadKey() End Sub End Module