SlideShare a Scribd company logo
object

Account

Saving
Account

Current
Account

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

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
Inheritance
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

PPT
Lecture19
PDF
The messy lecture
PDF
Accessing widget
PPTX
PDF
Windows Forms For Beginners Part - 2
PDF
Windows Forms For Beginners Part - 3
PPTX
Overview of .Net Framework 4.5
Lecture19
The messy lecture
Accessing widget
Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 3
Overview of .Net Framework 4.5

Similar to Inheritance (20)

PPT
20 Object-oriented programming principles
PPT
20. Object-Oriented Programming Fundamental Principles
DOCX
Introduction to object oriented programming concepts
PPTX
Object oriented programming Fundamental Concepts
PPT
session 24_Inheritance.ppt
PDF
Object oriented programming inheritance
PPTX
29csharp
PPTX
PDF
025 Summary.pdf
PPTX
Inheritance.pptx
PDF
Xamarin: Inheritance and Polymorphism
PPT
Classes2
PDF
Diving in OOP (Day 2): Polymorphism and Inheritance (Inheritance)
PPTX
Inheritance
PPTX
Module 6 : Essentials of Object Oriented Programming
PPTX
CSharp_03_Inheritance_introduction_with_examples
PDF
C# Summer course - Lecture 4
DOCX
Ganesh groups
PPTX
inheritance and polymorphism
PDF
2 BytesC++ course_2014_c11_ inheritance
20 Object-oriented programming principles
20. Object-Oriented Programming Fundamental Principles
Introduction to object oriented programming concepts
Object oriented programming Fundamental Concepts
session 24_Inheritance.ppt
Object oriented programming inheritance
29csharp
025 Summary.pdf
Inheritance.pptx
Xamarin: Inheritance and Polymorphism
Classes2
Diving in OOP (Day 2): Polymorphism and Inheritance (Inheritance)
Inheritance
Module 6 : Essentials of Object Oriented Programming
CSharp_03_Inheritance_introduction_with_examples
C# Summer course - Lecture 4
Ganesh groups
inheritance and polymorphism
2 BytesC++ course_2014_c11_ inheritance
Ad

More from Bhushan Mulmule (12)

PDF
Implementing auto complete using JQuery
PDF
Windows Forms For Beginners Part 5
PDF
Windows Forms For Beginners Part - 4
PDF
Windows Forms For Beginners Part - 1
PDF
NInject - DI Container
PDF
Dependency injection for beginners
PPTX
Understanding Interfaces
PPTX
Polymorphism
PPTX
Classes and objects
PPTX
Arrays, Structures And Enums
PPTX
Flow Control (C#)
PPTX
Getting started with C# Programming
Implementing auto complete using JQuery
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 1
NInject - DI Container
Dependency injection for beginners
Understanding Interfaces
Polymorphism
Classes and objects
Arrays, Structures And Enums
Flow Control (C#)
Getting started with C# Programming
Ad

Recently uploaded (20)

PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Approach and Philosophy of On baking technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Cloud computing and distributed systems.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Encapsulation theory and applications.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
The AUB Centre for AI in Media Proposal.docx
Diabetes mellitus diagnosis method based random forest with bat algorithm
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Electronic commerce courselecture one. Pdf
Empathic Computing: Creating Shared Understanding
Approach and Philosophy of On baking technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
cuic standard and advanced reporting.pdf
MYSQL Presentation for SQL database connectivity
Advanced methodologies resolving dimensionality complications for autism neur...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Cloud computing and distributed systems.
Agricultural_Statistics_at_a_Glance_2022_0.pdf
20250228 LYD VKU AI Blended-Learning.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation theory and applications.pdf

Inheritance