
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What is run time polymorphism in C#?
Runtime polymorphism has method overriding that is also known as dynamic binding or late binding. It is implemented by abstract classes and virtual functions.
Abstract Classes
Abstract classes contain abstract methods, which are implemented by the derived class.
Let us see an example of abstract classes that implements run time polymorphism −
Example
using System; namespace PolymorphismApplication { abstract class Shape { public abstract int area(); } class Rectangle: Shape { private int length; private int width; public Rectangle( int a = 0, int b = 0) { length = a; width = b; } public override int area () { Console.WriteLine("Rectangle class area :"); return (width * length); } } class RectangleTester { static void Main(string[] args) { Rectangle r = new Rectangle(10, 7); double a = r.area(); Console.WriteLine("Area: {0}",a); Console.ReadKey(); } } }
Example
Rectangle class area : Area: 70
Virtual Functions
When you have a function defined in a class that you want to be implemented in an inherited class(es), you use virtual functions. The virtual functions could be implemented differently in different inherited class and the call to these functions will be decided at runtime.
- Related Articles
- Using run-time polymorphism in Java
- What is compile time polymorphism in C#?
- What is the difference between compile time polymorphism and runtime polymorphism in java?
- What is polymorphism in C# ?
- What is Dynamic Polymorphism in C#?
- What is a static polymorphism in C#?
- What is Java run time environment?
- Difference between compile-time polymorphism and runtime polymorphism
- RTTI (Run-time type Information) in C++
- Explain Compile time and Run time initialization in C programming?
- What is the difference between compile time errors and run time errors in Java?
- RTTI (Run-time type Information) in C++ program
- What is role of Run-time Storage Management in compiler design?
- Polymorphism example in C++
- What are Java JVM Run-time Data Areas?

Advertisements