|
-
Nov 5th, 2005, 05:34 AM
#1
Thread Starter
Addicted Member
Polymorphism
I have read the book about OOP. It is said that Polymorphism is the ability to have the same method(the same name) in many classes.
I want to know that if I create two classes and each class has the same print method without using Inheritance or Interface. Is it called Polymorphism or not?
-
Nov 6th, 2005, 09:53 AM
#2
Re: Polymorphism
A polymorphic method is one that is declared in one class and overridden in another. If two methods in different classes have the same name but no other relationship then that is not polymorphism.
-
Nov 6th, 2005, 10:44 PM
#3
Re: Polymorphism
Either method overriding, or the ability to implement the same interface method differently, are considered polymorphism.
-
Nov 6th, 2005, 11:21 PM
#4
Thread Starter
Addicted Member
Re: Polymorphism
Thank jmcilhinney and penagate.
Sometimes my problem has been solved, but I want to get more ideas about this. And I also don't know how to mark it as resolved.
-
Nov 6th, 2005, 11:23 PM
#5
Re: Polymorphism
Maybe the FAQ can help you
-
Nov 7th, 2005, 06:03 AM
#6
Re: Polymorphism
VB Code:
class Parrot
public sub Speak()
...
end class
class Human
public sub Speak()
...
end class
This is NOT polymorphism because the two classes are totally unrelated.
However...
VB Code:
Class Mammal
Public Overridable Sub Speak()
End Sub
End Class
Class Human
Inherits Mammal
Public Overrides Sub Speak()
End Sub
End Class
IS polymorphism because Speak can be called on either a mammal (monkey say "ook") or a Human ("Hi, I'm a car salesman") without the compiler necessarily knowing at runtime which class type an object will be.
This also shows inheritance.
I don't live here any more.
-
Nov 7th, 2005, 03:31 PM
#7
Fanatic Member
Re: Polymorphism
Exactly! My professor keeps say that "Polymorphism is the ability to have the same method(the same name) in many classes."
This could only be the case when inheritance is used, like the example wossname has shown.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|