Polymorphism in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PolymorphismDetails
{
/// <summary>
/// Polymorphism :
/// 1. Polymorphism is defined as how to carry out different
processing steps by function having
/// same messages.
/// polymorphism
treats objects of related classes in generic manner
/// 2. In short polymorphism meaning passing a messages.
/// 3. Polymorphism comes from
greek word. Poly means Many and morphism means forms so it
/// becomes many
forms.
/// 4. in C# polymorphism is achieved withe help of virtual
keyword.
/// 5. Example. A teacher communicate with students and same
teacher communicate with principle.
/// Here teacher is
an object but the attribute is different at different position
/// 6. Person behaves as son in Home and same time person
behaves as Employee in office.
/// Person is an
object but the messages meaning way of communication is different at different
place
/// 7. ***************
There are two types of polymorphism is present in C# ******************
/// 1. Run time
Polymorphism => Which is also called as Late binding or dynamic binding
/// 2. Compile
time Polymorphism => Which is also called as Early binding or static binding
///
/// RUN TIME POLYMORPHISM :
/// 1. Run time polymorphism is also called as Late binding
or dynamic binding
/// 2. Run time polymorphism is achieved with the help of
Virtual keywords.
/// 3. Run time polymorphism is achieved by using Method
overriding.
/// 4. Method overriding allows us to have method in Base
class as well as in Derived class
/// with same name
and with same parameters
/// 5. By run time polymorphism, we can point to any derived
class from the object of base class at runtime
/// that shows the
ability of runtime binding.
/// 6. Through the reference variable of a base class, the
determination of the method to be called
/// is based on the
object being referred to by reference variable.
/// 7. Compiler would not be aware whether the method is
available for overriding the functionality or not. So compiler would not give
any error at compile time.
/// At runtime, it
will be decided which method to call and if there is no method at runtime,
/// it will give an error.
/// 9. If base class object is referenced to base class then
base class method is get called.
/// 10.If base class object is referenced to derived class
then derived class method is get called.
/// </summary>
class Program
{
static void Main(string[] args)
{
}
}
}
No comments:
Post a Comment