![]() ![]() But for a class to be a polymorphic class only two conditions need to be satisfied. And any object of your class is going to make it a polymorphic object. Now you gotta put your class against the polymorphic test:Īll these conditions hold true, meaning your class is a Polymorphic class. Imagine there is a class called Superhero. Here’s one cool IS-A relationship test to find out whether your class is polymorphic or not. When do you say a program is polymorphic? When your program passes more than one polymorphic test. We can achieve polymorphism by overriding and overloading a method as well. An object taking different forms so as to encourage code reuse is one of those typical examples of Java Polymorphism that we are going to see right away. Polymorphic Test and Referenceįirst, let us address the elephant in the room. Hopefully, by the time you reach the end, you would know everything there is to know about the concept of Java Polymorphism. It is closely associated with Inheritance.ĭon’t worry this chapter is entirely dedicated to it. ![]() Polymorphism is a major OOPS concept that you should know about if you wish to be a Java pro. That’s how you can make the most of a code without going about changing it every now and then. You reuse an existing code, you let your object take a different form, and you use the same bit all over again with different specifications. The second one sounds reasonable, doesn’t it? What do you do? Break down the entire house and build it all over again? Or simply append a room on any one side of your flat without deteriorating the already built structure. Now you have already created a three room kitchen flat, but suddenly you realize you need an extra room dedicated entirely for your DC and Marvel Collectibles. So we leverage whatever code we have parked in our system, with 0 modification in the existing code. To be available in different forms so as to help in reusing the same code over again is what Polymorphism is all about. If you look up the dictionary definition of Polymorphism, it is nothing but a condition to exist in different forms. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |