Programming C# 2.0, 3.0, 4.
Muhammed Ali Sakhi
Microsoft Certified Trainer
© PakDev.net
Agenda
Inheritance
Polymorphism
Sealed Classes
© PakDev.net
Inheritance
Ability to reuse, extend, and modify another
classes
You add new code to add the required features
Base class and derived class
Inherit from only one base class
© PakDev.net
Inheritance
The derived class implicitly gains all the
members of the base class, except constructors
and destructors
Private members are not accessible to child
classes
Protected members are accessible only to child
classes
© PakDev.net
Calling base Class Constructors
Constructor declaration must use base keyword
Use the base keyword
Derive class can declare members with same
name as those of base class members
© PakDev.net
Polymorphism
A derive class can override base class methods
Use the virtual keyword in base class
Use the override keyword in the child classes
Virtual methods cannot be static or private
Override methods cannot be static or override
You cannot override a non virtual method
Override methods cannot be explicitly virtual
You can override an override method
© PakDev.net
Using Sealed Classes
You cannot derive from a sealed class
Use the sealed keyword
© PakDev.net
Inheritance
Demo
© PakDev.net
Thank you
PakDev.net
© PakDev.net