Classes and Inheritance 靜宜大學資工系 蔡奇偉副教授 ©2011
大綱
Class Inheritance Base Class Derived Class
Accessing the Inherited Members
All Classes Are Derived from Class object
Hiding Members of a Base Class
Base Access keyword base
Using References to a Base Class An instance of a derived class consists of an instance of the base class, plus the additional members of the derived class. A reference to the derived class points to the whole class object, including the base class part. If you have a reference to a derived class object, you can get a reference to just the base class part of the object by casting the reference to the type of the base class by using the cast operator. The cast operator is placed in front of the object reference and consists of a set of parentheses containing the name of the class being cast to.
Virtual and Override Methods
Constructor Execution
Constructor Initializers
use a different constructor from the same class
Class Access Modifiers
Inheritance Between Assemblies
Member Access Modifiers
Regions Accessing a Member
Public Member Accessibility
Private Member Accessibility
Protected Member Accessibility
Internal Member Accessibility
Protected Internal Member Accessibility
Summary of Member Access Modifiers
Abstract Members An abstract member is a function member that is designed to be overridden.
Comparing Virtual and Abstract Members
Abstract Classes
Sealed Classes
Static Classes A static class is a class where all the members are static. Static classes are used to group data and functions that are not affected by instance data. A common use of a static class might be to create a math library containing sets of mathematical methods and values.
Extension Methods