Answer Posted / 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 |
Post New Answer View All Answers
What is inheritance in simple words?
Why it is called runtime polymorphism?
What does and I oop mean?
What is an interface in oop?
Why is abstraction used?
What does and I oop mean in text?
How do you answer polymorphism?
What does no cap mean?
Can a destructor be called directly?
What is destructor give example?
Write a java applet that computes and displays the squares of values between 25 and 1 inclusive and displays them in a TextArea box
to find out the minimum of two integer number of two different classes using friend function
Why is it so that we can have virtual constructors but we cannot have virtual destructors?
What is methods in oop?
What is class encapsulation?