|
||||||
| Java Tutorials Tutorials and Code for Java |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
||||
|
Re: Polymorphism
Very cool! +rep
__________________
CodeCall Blog | CodeCall Wiki | Shareware Programming is a branch of mathematics. My CodeCall Blog | My Personal Blog |
|
||||
|
Re: Polymorphism
Awesome!
![]() +rep
__________________
Questions and Answers | Online News and Social Bookmarking | Code and Text Collaboration General Chat Forum |
|
||||
|
Re: Polymorphism
Nice.
Inheritance can make things really easy but I don't quite see the point of overloading methods. The example above inherits from variables and then redefines the talk method. So then why not just define the talk method in each class. What is the point of overriding methods? |
|
||||
|
Re: Polymorphism
@chili5: He's showing that they can be overridden using method overloading. He needs to use overloaded methods because if he didn't, the "Human" object wouldn't have a "talk" method, in which case he couldn't call the talk method when referring to human objects, even if they are derived forms of human objects. The for loop is why he used overloading, however he did it in a similar way one would use interfaces, he didn't really need to use that, but he wasn't teaching interfaces.
![]() @Turk4n: Excellent work here. This leads me, naturally, to a question on the subject of method overloading: It would seem that methods are always able to be overloaded, similarly to how C++ would use the "virtual" keyword. In that case, is it possible to prevent a client programmer from using a polymorphed version of a method in your classes? For example, in C++ if you do not use the "virtual" keyword, when the object is referred to by it's base class, the function will not polymorph even if you DID overload it (see my C++ tut for clarification). Oh, and I give you my measely +rep! ![]()
__________________
On Hiatus... |
|
||||
|
Re: Polymorphism
Thank you
![]() Quote:
Quote:
![]() FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF FANKKKKKKKKKKKKKKKKS ![]()
__________________
![]() Hatsune Miku ~❤❤❤ 初音ミク。~❤❤❤ |
|
||||
|
Re: Polymorphism
Yes, if call the class.
Code:
MyClass MyC = new MyClass(); Ok, or was I unclear :X?
__________________
![]() Hatsune Miku ~❤❤❤ 初音ミク。~❤❤❤ |
|
||||
|
Re: Polymorphism
Yes, you must declare a method final, so i can't be overwritten.
By declaring the whole class final, it can't be extended at all. My teacher teached "the security hole" by programming a Door, that could be opened by certain Key, and then extended a Superkey from it, which could open any Door. ![]() Code:
final public class NoExtendingAtAll {
public void method(){
}
}
public class Someclass {
final public void noOverwritingMethod(){
}
}
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C++ Virtual Functions and Polymorphism | ZekeDragon | C Tutorials | 5 | 08-24-2009 02:51 AM |
| polymorphism | Siten0308 | C# Programming | 13 | 03-24-2009 05:57 AM |
| What are real time examples of nheritance, Polymorphism ,Encapsulation | rossen | C and C++ | 1 | 06-17-2008 08:39 AM |
| Please explain Polymorphism | Patrick | C and C++ | 3 | 10-09-2007 09:09 PM |
| polymorphism | Nightracer | General Programming | 6 | 07-26-2006 10:53 PM |
All times are GMT -5. The time now is 06:54 AM.
Amrosama.cc
Arekbulski.cc
Debtboy.cc
Guest.cc
Jaan.cc
James.cc
Mathx.cc
Tsz.cc
Vswe.cc