1 / 10

Polymorphism in Java

Polymorphism come from the two Greek words ‘poly’ meaning many and ‘morphs” meaning forms. The ability to exist in different form is called polymorphism. The same variable or method can perform different tasks; the programmer has the advantage of writing flexible code.

javatportal
Download Presentation

Polymorphism in Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Polymorphism in Java Method Overloading and Method Overriding Polymorphism in JavaMethod Overloading and Method Overriding Polymorphism come from the two Greek words ‘poly’ meaning many and ‘morphs” meaning forms. The ability to exist in different form is called polymorphism. The same variable or method can perform different tasks; the programmer has the advantage of writing flexible code.

  2. Types of Polymorphism Static polymorphism (compile time polymorphism) Dynamic polymorphism (Run time polymorphism) Polymorphism in JavaMethod Overloading and Method Overriding Static polymorphism (compile time polymorphism) If a method call is resolved at compile time that it is called static binding or earlier binding or static polymorphism or compile time polymorphism. Example- Method overloading and method overriding by using static method, private method and final method are example for static polymorphism.

  3. 2. Dynamic Polymorphism (Run Time Polymorphism) If a method call is resolved at the time of execution it is called dynamic binding or late binding or run time polymorphism. Example- Method overloading and method overriding by using instance method are example for dynamic binding. Polymorphism in JavaMethod Overloading and Method Overriding Binding Resolving a method call that is identifying a definition to be executed is called binding. In java method call resolve according to the following rules-

  4. Polymorphism in JavaMethod Overloading and Method Overriding In JVM assembly there are 4 instructions which are used by JRE for invoking method-

  5. Polymorphism in JavaMethod Overloading and Method Overriding Polymorphism in Java Method Overloading and Method Overriding

  6. Note:- To see assembly instruction in class file:- Syntax:- javap -c classFileName Example:- javap -c Calculate Method overloading Writing two or more method in the same class in such a way that each method has same name but with different method signature ( by varying there number of argument or varying the type of argument or varying the order of the argument) is called method overloading. Method overloading is one of the means of implementing polymorphism.

  7. Example-

  8. Method Overriding Writing two or more method in super and sub class such that the method have same name and same signature is called method overriding. Method overriding is one of the means of implementing polymorphism. Example-

  9. WWW.JAVATPORTAL.COM India's No. one Tutorials and a Solution of all Technology Address:-Sector 58 Noida, Uttar Pradesh 201301, India. Mobile: +91 9458548058, 8860449650 Email:sales.javatportal@gmail.com Website: http://www.javatportal.com

More Related