1 / 7

Polymorphism

Polymorphism. Bayu Priyambadha, S.Kom. Polymorphism. Poly = Many, Morph = form P olymorphism refers to a principle in biology in which an organism or species can have many different forms or stages

lynna
Download Presentation

Polymorphism

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 Bayu Priyambadha, S.Kom

  2. Polymorphism • Poly = Many, Morph = form • Polymorphismrefers to a principle in biology in which an organism or species can have many different forms or stages • Polymorphism is the capability of an action or method to do different things based on the object that it is acting upon • Overloading, overriding and dynamic method binding are three types of polymorphism.

  3. Overloading • Definetwo or more methods within the same class that share the same name, as long as their parameter declarations are different class Overloading {void test() {System.out.println("No parameters");}void test(int a, int b) {System.out.println("a and b: " + a + " " + b);}void test(float a) {System.out.println("Inside test(double) a: " + a);}}

  4. Overriding • Abilityto define a behavior that's specific to the sub class type class Animal { public void move() { System.out.println("Animals can move"); } } class Dog extends Animal { public void move() { System.out.println("Dogs can walk and run"); } }

  5. Dynamic Binding • has definition A mechanism by which, when the compiler can't determine which method implementation to use in advance, the runtime system (JVM) selects the appropriate method at runtime, based on the class of the object • has definition The process of binding a call to a particular method. This is performed dynamically at run-time due to the presence of polymorphism

  6. Static Binding • applies todata valuesand static members • has definition A mechanism by which the compiler determines which method implementation to use in advance, based on the type of the reference (regardless of the actual class of the object)

  7. Thanks...

More Related