SlideShare a Scribd company logo
1 of 24
object

Account

Saving
Account

Current
Account

Bhushan Mulmule
bhushan.mulmule@gmail.com
bhushan.mulmule@dotnetvideotutorial.com
www.dotnetvideotutorial.com


Part I
◦ Inheritance: When, Why, How
◦ Inheritance in .NET Framework
◦ Inheritance Demo Example



Part II
◦ Constructor Flow in Inheritance



Part III
◦ Access Modifiers: private, public, protected, internal, protected internal
www.dotnetvideotutorial.com
www.dotnetvideotutorial.com
Inheritance enables you to create new classes that reuse, extend,
and modify the behavior that is defined in other classes.
Base class

class MyBase
{
private int field1;
public void fun1() { }
}

Derived class

class MyDerived : MyBase
{
private int field2;
public void fun2() { }
}

Object of
MyDerived

obj
field1
www.dotnetvideotutorial.com

field2
www.dotnetvideotutorial.com
OnRollEmployee
EmpNo
Name
Department

Designation
BasicSalary
HRA
GrossSalary
PF

OffRollEmployee
EmpNo
Name
Department
Designation
PerHourRate
WorkedHours
NetSalary

NetSalary
www.dotnetvideotutorial.com
Employee

Generalized Base Class

EmpNo
Name
Department
Designation
NetSalary

Specialized Derived Class

OffRollEmployee

OnRollEmployee
BasicSalary

PerHourRate

HRA

WorkedHours

GrossSalary
PF
www.dotnetvideotutorial.com
object

object

Account

StackHolder

Client

Customer

Supplier

www.dotnetvideotutorial.com

Saving
Account

Current
Account
www.dotnetvideotutorial.com
www.dotnetvideotutorial.com
www.dotnetvideotutorial.com
www.dotnetvideotutorial.com


inheritance hierarchy represents an "is-a" relationship and not a
"has-a" relationship.



can reuse code from the base classes.



need to apply the same class and methods to different data
types.



The class hierarchy is reasonably shallow, and other developers
are not likely to add many more levels.



want to make global changes to derived classes by changing a
base class.

www.dotnetvideotutorial.com


Every class directly of indirectly derives from object
class



Multiple class Inheritance is not allowed.



Multilevel is obvious!



Multiple interface implementation is possible.

www.dotnetvideotutorial.com


Part I
◦ Inheritance: When, Why, How
◦ Shadowing
◦ Inheritance Demo Example



Part II
◦ Constructor Flow in Inheritance



Part III
◦ Access Modifiers: private, public, protected, internal, protected internal
www.dotnetvideotutorial.com



Constructor never get derived
Always base class constructor executes first.

www.dotnetvideotutorial.com
class MyBase
{
protected int no1, no2;

class MyDerived : MyBase
{
private int no3;

public MyBase()
{
}

public MyDerived() : base()
{
}

public MyBase(int n1,int n2)
{
this.no1 = n1;
this.no2 = n2;
}

public MyDerived(int n1,int n2,int n3)
: base(n1,n2)
{
this.no3 = n3;
}

}

}

Client Code
MyDerived obj1 = new MyDerived();
MyDerived obj2 = new MyDerived(10, 20, 30);

no1

no2

no3
www.dotnetvideotutorial.com


Part I
◦ Inheritance: When, Why, How
◦ Shadowing
◦ Inheritance Demo Example



Part II
◦ Constructor Flow in Inheritance



Part III
◦ Access Modifiers: private, public, protected, internal, protected internal
www.dotnetvideotutorial.com
Access modifiers are keywords used to specify the declared
accessibility of a member or a type
public

• Access is not restricted.

private

• Access is limited to the containing type.

protected
internal
protected internal

• Access is limited to the containing class or types derived from the
containing class.

• Access is limited to the current assembly.

• Access is limited to the current assembly or types derived from the
containing class.
www.dotnetvideotutorial.com
Assembly - 1

Assembly - 2

class A
{
private int no1;
protected int no2;
internal int no3;
protected internal int no4;
public int no5;
}
class B : A
{
}
class C
{
}

class D : A
{
}
class E
{
}

What is accessible where?
no1

•A

no2

•A, B, D

no3

•A, B, C

no4

•A, B, C, D

no5

•A, B, C, D, E

www.dotnetvideotutorial.com
Bhushan Mulmule
bhushan.mulmule@dotnetvideotutorial.com
www.dotnetvideotutorial.com

More Related Content

Similar to Inheritance

Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
Jonathan Wage
 

Similar to Inheritance (20)

Libertyvasion2010
Libertyvasion2010Libertyvasion2010
Libertyvasion2010
 
Python_Unit_2 OOPS.pptx
Python_Unit_2  OOPS.pptxPython_Unit_2  OOPS.pptx
Python_Unit_2 OOPS.pptx
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
 
Microservices: Improving the autonomy of our teams with Event-Driven Architec...
Microservices: Improving the autonomy of our teams with Event-Driven Architec...Microservices: Improving the autonomy of our teams with Event-Driven Architec...
Microservices: Improving the autonomy of our teams with Event-Driven Architec...
 
Clean code
Clean codeClean code
Clean code
 
C++ oop
C++ oopC++ oop
C++ oop
 
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
 
Plone pwns
Plone pwnsPlone pwns
Plone pwns
 
What is inheritance
What is inheritanceWhat is inheritance
What is inheritance
 
Constructors
ConstructorsConstructors
Constructors
 
iPhone Seminar Part 2
iPhone Seminar Part 2iPhone Seminar Part 2
iPhone Seminar Part 2
 
Object
ObjectObject
Object
 
Unit testing - 9 design hints
Unit testing - 9 design hintsUnit testing - 9 design hints
Unit testing - 9 design hints
 
CDI 2.0 Deep Dive
CDI 2.0 Deep DiveCDI 2.0 Deep Dive
CDI 2.0 Deep Dive
 
CDI and Weld
CDI and WeldCDI and Weld
CDI and Weld
 
CDI and Weld
CDI and WeldCDI and Weld
CDI and Weld
 
Magic methods
Magic methodsMagic methods
Magic methods
 
Constructor and destructor
Constructor and destructorConstructor and destructor
Constructor and destructor
 
7494609
74946097494609
7494609
 

More from Bhushan Mulmule

More from Bhushan Mulmule (11)

Implementing auto complete using JQuery
Implementing auto complete using JQueryImplementing auto complete using JQuery
Implementing auto complete using JQuery
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5
 
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4
 
Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1
 
NInject - DI Container
NInject - DI ContainerNInject - DI Container
NInject - DI Container
 
Dependency injection for beginners
Dependency injection for beginnersDependency injection for beginners
Dependency injection for beginners
 
Understanding Interfaces
Understanding InterfacesUnderstanding Interfaces
Understanding Interfaces
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Arrays, Structures And Enums
Arrays, Structures And EnumsArrays, Structures And Enums
Arrays, Structures And Enums
 
Flow Control (C#)
Flow Control (C#)Flow Control (C#)
Flow Control (C#)
 
Getting started with C# Programming
Getting started with C# ProgrammingGetting started with C# Programming
Getting started with C# Programming
 

Recently uploaded

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
Enterprise Knowledge
 

Recently uploaded (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Inheritance