Last active
January 3, 2016 18:09
-
-
Save rajeevprasanna/8500736 to your computer and use it in GitHub Desktop.
Super class method invoker
This file contains 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 polymorphism.superclassMethodInvoker; | |
public class Animal { | |
public void eat() { | |
} | |
public void printYourself() { | |
// Useful printing code goes here | |
} | |
} |
This file contains 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 polymorphism.superclassMethodInvoker; | |
//Refer : https://gist.github.com/rajeevprasanna/8500736 | |
public class Horse extends Animal { | |
public void printYourself() { | |
// Take advantage of Animal code, then add some more | |
super.printYourself(); // Invoke the superclass // (Animal) code | |
// Then do Horse-specific | |
// print work here | |
// Using super to invoke an overridden method only applies to instance | |
// methods. (Remember, static methods can't be overridden.) | |
// If you try to printYourself method using super without extending | |
// Animal class, it will throw compile time error. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment