Created
October 6, 2015 10:50
-
-
Save smamran/6e907a0229d91e3caf2d to your computer and use it in GitHub Desktop.
Dynamic Method Dispatching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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