Professional Documents
Culture Documents
Introduction to
Inheritance
1
Objectives
2
Objectives
3
Objectives
4
Understanding the Concept of Inheritance
5
Understanding the Concept of Inheritance
• An Employee class
6
Understanding the Concept of Inheritance
8
Understanding Inheritance Terminology
9
Extending Classes
10
Using the protected Access Specifier
11
Using the protected Access Specifier
13
Overriding Superclass Methods
16
Understanding a Subclass Object “is an”
Instance of the Superclass
• Every subclass object “is a” specific instance of both the
subclass and the superclass
• You can assign a subclass object to an object of any of
its superclass types. When you do so, C# makes an
implicit conversion from subclass to superclass
• C# also makes implicit conversions when casting one
data type to another
17
Using the Object Class
18
Using the Object Class
19
Using the Object Class
20
Working with Superclasses that have
Constructors
• When you instantiate an object that is a member of a
subclass, you actually call two constructors
• When you create any subclass object, the base class
constructor must execute first
21
Using Superclass Constructors that Require
Arguments
• When you use a class as a superclass, and the class
has a constructor that requires arguments, then you
must make sure that any subclasses provide the
superclass constructor with the proper arguments
• The format of the statement that calls a superclass
constructor is base(list of arguments)
• C# does not allow you to call the superclass constructor
by name, it must be called using the base keyword
22
Creating and Using Abstract Classes
23
Creating and Using Abstract Classes
• Animal class
24
Creating and Using Abstract Classes
25
Creating and Using Abstract Classes
26
Creating and Using Interfaces
27
Recapping the Benefits of Using Inheritance
28
Chapter Summary
29
Chapter Summary
30
Chapter Summary
31