Skip to content

Instantly share code, notes, and snippets.

@smamran
Created October 6, 2015 10:50
Show Gist options
  • Select an option

  • Save smamran/6e907a0229d91e3caf2d to your computer and use it in GitHub Desktop.

Select an option

Save smamran/6e907a0229d91e3caf2d to your computer and use it in GitHub Desktop.
Dynamic Method Dispatching
package slidenerd.javaoop;
/**
* Created by Microsoft on 10/6/2015.
*/
public class DynamicMethodDispatch {
public static void main(String[] args) {
// Checking ------------------
// Compile time Runtime
Animal an = new Dog();
an.move(); // Dog Moves
}
}
class Animal {
public void move() {
System.out.println("Animal Moves");
}
}
class Dog extends Animal {
// Method Overriding
public void move() {
// calling parent class move by
// super.move();
System.out.println("Dog Moves");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment