polymorphism is popularly called as one interface,multiple functions.
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
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.
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.
polymorpihsm ->one name, many form.
have 2 types : 1. Compile time, 2 Run time
1 compile time: also called overloadinghave 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.
The single sentence definition of polymorphism is"The ability to take more than one form.".__________________________________________________________MBA consultants in India
Polymorphism: It's derived from a Greek word, where poly means many morph means Faces/Behaviors.
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
1. function overloading,
2. Runtime polymorphism --Using Interface reference,
interface name I ,abstract Method();
implimenting classes A,B
objA= new A();
objB= new B();
Polymorphism means Poly=manymorphism=form Polymorphism is achieve by using function overloading.
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)
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.
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");
Multiple use of single form is known as poly...
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.