Skip to content

Instantly share code, notes, and snippets.

@rajeevprasanna
Last active January 3, 2016 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajeevprasanna/8500736 to your computer and use it in GitHub Desktop.
Save rajeevprasanna/8500736 to your computer and use it in GitHub Desktop.
Super class method invoker
package polymorphism.superclassMethodInvoker;
public class Animal {
public void eat() {
}
public void printYourself() {
// Useful printing code goes here
}
}
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