Interviews - C# Corner

What is Polymorphism? How does VB.NET/C# achieve polymorphism?
By in OOP/OOD on Aug 05, 2006
  • manoj prabakaran
    Apr, 2012 20

    The definition of polymorphism is when different types of objects use the method or properties with the same name. Therefore, the programmer doesn't need to know the exact type of an object while coding the application. The precise behavior of a method or property is determined at run-time.

    • 0
  • johnpaulmathew
    Jul, 2011 19

    The single sentence definition of polymorphism is"The ability to take more than one form.".<br><br>__________________________________________________________<br><a href="">MBA consultants in India</a><br>

    • 0
  • Shivprasad
    Feb, 2011 6

    <P>This is a nice and simple <A href="">OOP interview question</A>. As the name says POLY (Many) MORPHISM (Change). Polymorphism is the ability of the object to behave differently under different conditions. For instance a simple user object can behave as a admin user or as a simple user depending on conditions.</P> <P>There are two ways of doing polymorphism dynamic and static. Static polymoprhism is achieved by using method overloading and dynamic polymorphism is acheived by using method overloading. Please note do confuse with overloading and overriding while answering this question. Many .NET developers make a niceversa statement leading to lot of confusion.</P> <P>See my 50 .<A href="">NET&nbsp; and ASP.NET Interview questions</A></P>

    • 0
  • AmaranathaReddy Ambati
    Nov, 2010 28

    Polymorphism: It's derived from a Greek word, where poly means many morph means Faces/Behaviors.<div>Same function/operator will show different behaviours when passed different types of values or different number of values.</div><div>Types of polymorphism:There are 2 types:-</div><div>1. Static polymorphism/Early Binding/Compile time&nbsp;polymorphism.</div><div>2. Dynamic&nbsp;polymorphism/Late Binding/Run time&nbsp;polymorphism.</div><div><br></div><div>Static&nbsp;polymorphism is achieved using i)&nbsp;Function&nbsp;overloading ii) Operator overloading</div><div><br></div><div>Dynamic&nbsp;polymorphism is achieved using&nbsp;i)&nbsp;Function&nbsp;overloading<br><div><br></div></div>

    • 0
  • vaishnavi ranganathan
    Oct, 2010 10

    polymorphism is popularly called as one interface,multiple functions.<div>The OOP allows object to respond differently for the same message.</div><div>It is an entity tat exists in different form simultaneously.</div><div><br></div><div>Static polymorphism</div><div>-&gt;function overloading</div><div>-&gt;operator overloading</div><div>-&gt;constructor overloading</div><div>&nbsp;&nbsp; &nbsp;1&gt;instance constructor</div><div>&nbsp;&nbsp; &nbsp;2&gt;static constructor</div><div><br></div><div>dynamic polymorphism</div><div>&nbsp;&nbsp;1)abstract class</div><div>&nbsp;&nbsp;2)virtual function</div><div>&nbsp;&nbsp;3)delegates</div><div><br></div><div><br></div><div>-&gt;</div>

    • 0
  • rizwanrizwan rizwanrizwan
    Sep, 2010 7

    Hanumantha Rao <br> Jun 04, 2007 <table><tbody><tr><td class="LeftBarLine"> <br></td> <td id="ctl00_ContentPlaceHolder1_GridViewAnswers_ctl07_td2" class="NormalText" width="500"> <p>In oops world&nbsp; the polymorphisam is to ability inherits methods and properties of baseclass into derived class.</p> <p>Example of polymorphisam is </p> <p>public class Addres_Details</p> <p>{</p> <p>//here comes default construtor</p> <p>//Now I am defines one method </p> <p>&nbsp; public virtual void&nbsp; add_nam</p></td></tr></tbody></table>

    • 0
  • Reva Sahu
    Dec, 2009 31

    <PRE>1. function overloading, 2. Runtime polymorphism --Using Interface reference, EX: interface name I ,abstract Method(); implimenting classes A,B ref I; objA= new A(); objB= new B(); runtime objA=I objA.Method(); objB=I; objB.Method();</PRE>

    • 0
  • anant patil
    Sep, 2009 26

    Polymorphism means <br>Poly=many<br>morphism=form<br>&nbsp;Polymorphism is achieve by using function overloading.<br><br>

    • 0
  • Eranda Horanagama
    Jan, 2009 23

    Polymorphism means ability to take more than one form.<br><br> and C# achieve polymorphism through inheritance.<br>When class is inheriting by generalized class in to a specialized class,it includes the behavior of the generalized class. But if we need some different kind of implementation rather than which provides by the top class we can implement it with our specialized class without making any changes to the name.<br>&nbsp;<br>Polymorphism comes in to action with dynamic binding, so it's important to identify which object to have which behavior. ( and C# both are default to dynamic binding)<br><br>

    • 0
  • Gurjinder Singh Brar
    Aug, 2007 11

    Polymorphism refers to the ability to assume different forms. In OOP, it indicates a language’s ability to handle objects differently based on their runtime type. When objects communicate with one another, we say that they send and receive messages. The advantage of polymorphism is that the sender of a message doesn’t need to know which class the receiver is a member of. It can be any arbitrary class. The sending object only needs to be aware that the receiving object can perform a particular behavior.

    A classic example of polymorphism can be demonstrated with geometric shapes. Suppose we have a Triangle, a Square, and a Circle. Each class is a Shape and each has a method named Draw that is responsible for rendering the Shape to the screen. With polymorphism, you can write a method that takes a Shape object or an array of Shape objects as a parameter (as opposed to a specific kind of Shape). We can pass Triangles, Circles, and Squares to these methods without any problems, because referring to a class through its parent is perfectly legal. In this instance, the receiver is only aware that it is getting a Shape that has a method named Draw, but it is ignorant of the specific kind of Shape. If the Shape were a Triangle, then Triangle’s version of Draw would be called. If it were a Square, then Square’s version would be called, and so on.

    Here is detail the how OOP languages achieve Polymorphism in different ways
    Polymorphism in OOP languages
    OOPS Concepts & Faqs

    • 0
  • Shaik Hanumantha Rao
    Jun, 2007 4

    In oops world  the polymorphisam is to ability inherits methods and properties of baseclass into derived class.

    Example of polymorphisam is

    public class Addres_Details


    //here comes default construtor

    //Now I am defines one method

      public virtual void  add_name



    //Now i am defining new class and inherits the Address_details class

    public class New_address_Details:Address_Details


    public override void add_name()


    console.writeln("This  is the Example of the Polymorphisam");





    • 0
  • Dec, 2006 12

    Poly means many and morph means form. Thus, polymorphism refers to being able to use many forms of a type without regard to the details.

    Polymorphism Overview : -When a derived class inherits from a base class, it gains all the methods, fields, properties and events of the base class. To change the data and behavior of a base class, you have two choices: you can replace the base member with a new derived member, or you can override a virtual base member.

    Replacing a member of a base class with a new derived member requires the new keyword. If a base class defines a method, field, or property, the new keyword is used to create a new definition of that method, field, or property on a derived class. The new keyword is placed before the return type of a class member that is being replaced.
    When the new keyword is used, the new class members are called instead of the base class members that have been replaced. Those base class members are called hidden members. Hidden class members can still be called if an instance of the derived class is cast to an instance of the base class.


    Generally, the ability to appear in many forms. In object-oriented programming, polymorphism refers to a programming language's ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes.

    For example, given a base class shape, polymorphism enables the programmer to define different area methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the area method to it will return the correct results. Polymorphism is considered to be a requirement of any true object-oriented programming language.

    • 0
  • Nizam
    Sep, 2006 1

    polymorpihsm ->one name, many form.

    have 2 types : 1. Compile time, 2 Run time

    1 compile time: also called overloading
    have 3 types. 1. Constructor overloading(i.e.,with same constructor name and different no of arguments or different datat types or both ) 2 Function overloading(i.e.,with same function name and different no of arguments or different datat types or both)

    3. operator overloading: exaample : String s = "James";

    s = s + "Bond";

    Runtime poly: is achieved by overridding parent class method:

    This is called Dynamic method dispatch.





    • 0
  • Raj
    Aug, 2006 30

    Multiple use of single form is known as poly...

    • 0
  • farshad
    Aug, 2006 5

    If I remember correctly, it is something like when you have the same method names but different implementations.

    For example in the base class there is a method called PrintMessage().
    In the derived calss there is the same method name.

    The way that this can be achived without errors is to have Virtual in the base class and override in the derived class for the method names.

    I think this should give you a basic understanding of polymosrphism. I am not too sure though.

    • 0

Unlimited Flat-Free License

Most Popular Companies

Most Popular Job Functions