|
|
||||||||
|
||||||||
|
||||||||
|
|
|
| Polymorphism is one of the key concepts in Object Oriented Programming. Using polymorphism enables the programmer to design software that is easily extensible which, in turn, prolongs the life of that program. | ![]() |
| |
| • Comment On Tutorial |
• View Tutorial
• Report Broken Link |
|
|
- By:
- shravan
Mar 21st, 2006 at 07:33 AMImports System.Console Module Module1 Class shan Inherits shan1 Shadows Function fun() As Integer WriteLine(" in derived ") End Function End Class Class shan1 Function fun() As Integer WriteLine(" in base") End Function End Class Sub Main() 'Dim temp As shan1 Dim temp As Object Dim temp1 As New shan Dim temp2 As New shan temp = temp1 temp.fun() temp2 = temp temp2.fun() ReadLine() End Sub End Module see in the vb.net polymorphism is designed in such a manner which is entirely different from other language . well i am in learning phase so please do correct me if i get wrong somewhere here in the code if i make a object class reference and put a instance of a class shan and then call the function fun() then it is calling that function which it should not call since there is no function fun() defined in the object class so it should give error such as "no such member in the object class" but rather its calling . now the interesting thing is if u do the same thing by using the base and derived class (shown in the code ) then it will give the error ( what i stated above) and it is working fine. so why it is behaving differently for the object class. one more thing i want to express temp = temp1 temp.fun() temp2 = temp it should not work or should give warning or should demand explict conversion but it is converting simply without any problem ??