Home | Submit an interview question | Filter by category | Filter by job function | Filter by company
 
Member Information
User Id
Password
 
Forgot Password
Technology Category
.NET (1202)
Languages (103)
Database (146)
Operating System (48)
Reporting (5)
Third-Party Tools (2)
Testing (91)
OOP (75)
Web Development (40)
Design Patterns (89)
General (9)
Networking (88)
Hardware (63)
Brain Exercise (2)
Others (37)
 Our Network
.NET Heaven
C# Corner
Interview Corner
Longhorn Corner
Mindcracker
VB.NET Heaven
Home » OOP » OOP
What is Polymorphism? How does VB.NET/C# achieve polymorphism?
Posted by Aug 05, 2006
Viewed : 25119 times
Major Category : OOP
Minor Category : Others
Total Replies : 8
Become a Sponsor
 EDITORIAL ANSWER  
No Reply Yet
 ANSWERS BY USERS  
anant patil
Sep 26, 2009
Polymorphism means
Poly=many
morphism=form
 Polymorphism is achieve by using function overloading.

Udeshika Horanagama
Jan 23, 2009
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)

Gurjinder Singh Brar
Aug 11, 2007

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
Shaik 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_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");

}

}
}

 

 


Dec 12, 2006

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.

Nizam
Sep 01, 2006

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

 

 

Raj
Aug 30, 2006
Multiple use of single form is known as poly...

Aug 05, 2006

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.

  
1

 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Advertise with us
Current Version: 2.2009.3.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved