Revised: Fri May 06 14:33:08 CDT 2016
This page is part of a Book titled XNA Game Studio .
Table of Contents
- Table of Contents
- Preface
- General background information
- Preview
- Discussion and sample code
- Run the program
- Run my program
- Summary
- Miscellaneous
- Complete program listing
Preface
This module is one in a collection of modules designed primarily for teaching GAME 1343 Game and Simulation Programming I at Austin Community College in Austin, TX. These modules are intended tosupplement and not to replace the textbook.
An earlier module titled Getting Started provided information on how to get started programming with Microsoft's XNA Game Studio.
Object-oriented programs exhibit three main characteristics:
- Encapsulation
- Inheritance
- Polymorphism
I have explained encapsulation, inheritance, and compile-time polymorphism in earlier modules. Before I can explain runtime polymorphism, however, I need tostep back and explain some concepts involving type conversion, casting, and assignment compatibility.
Viewing tip
I recommend that you open another copy of this module in a separate browser window and use the following links to easily find and view the Listings while you are reading about them.
Listings
- Listing 1 . Source code for class A.
- Listing 2 . Source code for class B.
- Listing 3 . Source code for class C.
- Listing 4 . Beginning of the class named Polymorph02.
- Listing 5 . Try to call method m on variable var.
- Listing 6 . Try a downcast to type A.
- Listing 7 . Try a downcast to type B.
- Listing 8 . Assign var to v1.
- Listing 9 . Cannot be assigned to C.
- Listing 10 . Another failed attempt.
- Listing 11 . Project Polymorph02.
General background information
Type conversion
This module explains type conversion for both primitive and reference types.
Assignment compatibility
A value of a particular type may be assignment-compatible with a variable of another type. If so, the value can be assigned directly to the variable.