Documente Academic
Documente Profesional
Documente Cultură
Introduction to
Inheritance
1
Objectives
Objectives
How to access superclass methods from a
subclass
How a subclass object is an instance of the
superclass
About the Object class
How to work with superclasses that have
constructors
How to work with superclass constructors that
require arguments
3
Objectives
How to create and use abstract classes
How to create and use interfaces
Learn the benefits of inheritance
An Employee class
Extending Classes
When you create a class that is an extension or child of
another class, you use a single colon between the
derived class name and its base class name
Inheritance works in one direction
10
11
13
16
17
18
20
21
22
Animal class
24
27
28
Chapter Summary
Inheritance is the principle that you can apply your
knowledge of a general category to more specific objects
A class that is used as a basis for inheritance is called a
base class
When you create a class that is an extension or child of
another class, you use a single colon between derived
class name and its base class name
If you could use private data outside of its class, the
principle of information hiding would be destroyed
29
Chapter Summary
You can declare a child class method with the same
name and argument list as a method within its parent
class
When a subclass overrides a parent class method and
you want to use the parent class version, you can use
the keyword base to access the parent class method
Every subclass object is a specific instance of both the
subclass and the superclass
Every class you create in C# derives from a single class
named System.Object
30
Chapter Summary
When you instantiate an object that is a member of a
subclass, you actually call two constructors
When you use a class as a superclass, and the class
has a constructor that requires arguments, then within
the header of the subclass constructor you must provide
values for any arguments required by the base class
constructor
An abstract class is one from which you cannot create
any concrete objects
C# provides an alternative to multiple inheritance known
as the interface
31