Polymorphism with an example?

Answers were Sorted based on User's Feedback



Polymorphism with an example?..

Answer / yamuna mathew

samne function behave differntily on different occasion

Is This Answer Correct ?    14 Yes 3 No

Polymorphism with an example?..

Answer / bilal dooply

Polymorphism is a property in which a single object can have more than 1 form.

Example [Code in VB.NET]:

Class Animals
'Walk() is declared Overridable

Overridable Public Sub Walk()
Console.Writeline ("Walking")
End Sub
End Class

Class Dog
Inherits Animals
'Let us make Dog is walking

'Walk() is overriding Walk() in its base class (Animals)

Overrides Public Sub Walk()
Console.Writeline ("Walking")
'Important: As you expect, any call to Walk() inside this class
'will invoke the Walk() in this class. If you need to
'call Walk() in base class, you can use MyBase keyword.
'Like this

'Mybase.Speak()

End Sub
End Class

Class MainClass
'Our main function

Shared Sub Main()
'Let us define Tommy as a Animal (base class)

Dim Tommy as Animals
'Now, I am assiging an Indian (derived class)

Tommy = new Dogs
'The above assignment is legal, because

'Dogs IS_A Animals.

'Now, let me call Walk as

Tommy.Walk()
'Which Walk() will work? The Walk() in Dogs, or the

'Walk() in Animals?

'The question arises because, Tommy is declared as a Animals,

'but an object of type Dogs is assigned to Tommy.

'The Answer is, the Walk() in Dogs will work. This is because,

'most object oriented languages like Vb.net can automatically

'detect the type of the object assigned to a base class variable.

'This is called Polymorphism

End Sub
End Class

Is This Answer Correct ?    7 Yes 0 No

Polymorphism with an example?..

Answer / vivin

It means ability to take more than 1 form.

(ex)consider the operation of addition,

For 2 numbers it will generate sum{2 + 3 = 5} then
for 2 strings it will concatenate (vivin + durai = vivindurai)

Is This Answer Correct ?    6 Yes 2 No

Polymorphism with an example?..

Answer / rajeesh

polymorphism is a programming language feature that allows
values of different data types to be handled using a uniform
interface.

Is This Answer Correct ?    4 Yes 1 No

Polymorphism with an example?..

Answer / rajdeep gupta

to call the overloaded function via object is known as
polymorphism.There are two types of polymorphism
1-Dynamic polymorphism
2-static polymorphism

static polymorphism(early binding)

there in only one class is sufficient to call the overloaded
function.it is predefine that which function want to be call.
that means the linking between function call and object is
resolved at compile time is known as static polymorphism.

dynamic polymorphism(late binding)
class model should be based on inheritance model.virtual
function is used for it.
that means the linking between function call and object is
resolved at run time is known as dynamic polymorphism.

Is This Answer Correct ?    3 Yes 0 No

Polymorphism with an example?..

Answer / viveka nanda reddy.

The term 'poly' refers "many"& 'Morphism' refers "forms".In
other words the polymorphism refers to the same name having
different attributes(Behaviour).

Is This Answer Correct ?    3 Yes 0 No

Polymorphism with an example?..

Answer / anil

polymorphism means implementing different functionality's
with the same name and different type of arguments and
different number of parameters.We can achieve polymorphism
using function overloading and function overriding.

Is This Answer Correct ?    1 Yes 0 No

Polymorphism with an example?..

Answer / sanjeevkumar.v

different form of functions

Is This Answer Correct ?    3 Yes 8 No

Post New Answer

More OOPS Interview Questions

What is variable example?

0 Answers  


Question: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date.

0 Answers  


what is an qt4 interface?

1 Answers   IBM,


is java purely oop Language?

49 Answers   HCL, Infosys, TCS,


How is exception handling carried out in c++?

3 Answers  






c++ program to swap the objects of two different classes

0 Answers  


explain sub-type and sub class? atleast u have differ it into 4 points?

0 Answers   Infosys,


i^=j; j^=i; i^=j; value of i,j

1 Answers  


What is abstraction encapsulation?

0 Answers  


what is virtual function?

26 Answers   Aspire, HP, Infosys, RoboSoft, TCS,


Differences between inline functions and non-inline functions?

4 Answers   Ness Technologies,


What is the advantage of oop over procedural language?

0 Answers  


Categories