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.".

    __________________________________________________________
    MBA consultants in India

    • 0
  • Shivprasad
    Feb, 2011 6

    This is a nice and simple OOP interview question. 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.

    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.

    See my 50 .NET  and ASP.NET Interview questions

    • 0
  • AmaranathaReddy Ambati
    Nov, 2010 28

    Polymorphism: It's derived from a Greek word, where poly means many morph means Faces/Behaviors.

    Same function/operator will show different behaviours when passed different types of values or different number of values.
    Types of polymorphism:There are 2 types:-
    1. Static polymorphism/Early Binding/Compile time polymorphism.
    2. Dynamic polymorphism/Late Binding/Run time polymorphism.

    Static polymorphism is achieved using i) Function overloading ii) Operator overloading

    Dynamic polymorphism is achieved using i) Function overloading

    • 0
  • vaishnavi ranganathan
    Oct, 2010 10

    polymorphism is popularly called as one interface,multiple functions.

    The OOP allows object to respond differently for the same message.
    It is an entity tat exists in different form simultaneously.

    Static polymorphism
    ->function overloading
    ->operator overloading
    ->constructor overloading
        1>instance constructor
        2>static constructor

    dynamic polymorphism
      1)abstract class
      2)virtual function
      3)delegates


    ->

    • 0
  • rizwanrizwan rizwanrizwan
    Sep, 2010 7

    Hanumantha Rao
    Jun 04, 2007


    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_nam

    • 0
  • Reva Sahu
    Dec, 2009 31

    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();

    • 0
  • anant patil
    Sep, 2009 26

    Polymorphism means
    Poly=many
    morphism=form
     Polymorphism is achieve by using function overloading.

    • 0
  • Eranda Horanagama
    Jan, 2009 23

    Polymorphism means ability to take more than one form.

    VB.net and C# achieve polymorphism through inheritance.
    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.
     
    Polymorphism comes in to action with dynamic binding, so it's important to identify which object to have which behavior. (VB.net and C# both are default to dynamic binding)

    • 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.

    or

    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.

    regards

    Nizam

    • 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


Most Popular Job Functions


MOST LIKED QUESTIONS