Last active
October 30, 2018 06:35
-
-
Save lizettepreiss/1c3118a37fd206f2caa29ccbe61e1215 to your computer and use it in GitHub Desktop.
Java Inheritance Demo. Which parent's methods in a hierarchy of inheritance get called.
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
See Child.java, Parent.java, GrandParent.java, GreatGrandParent.java, InheritanceDemo.java |
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 preiss.inheritancedemo; | |
public class Child extends Parent{ | |
@Override | |
public void handle(){ | |
System.out.println("Child.handle"); | |
super.handle(); | |
} | |
} |
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 preiss.inheritancedemo; | |
public abstract class GrandParent extends GreatGrandParent{ | |
@Override | |
public void doStuff(){ | |
System.out.println("GrandParent.doStuff"); | |
} | |
} |
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 preiss.inheritancedemo; | |
public abstract class GreatGrandParent { | |
public abstract void doStuff(); | |
public void handle(){ | |
System.out.println("GreatGrandParent.handle"); | |
doStuff(); | |
} | |
} |
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 preiss.inheritancedemo; | |
public class InheritanceDemo { | |
public static void main(String[] args) { | |
Child cw = new Child(); | |
cw.handle(); | |
} | |
} |
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 preiss.inheritancedemo; | |
public class Parent extends GrandParent{ | |
@Override | |
public void doStuff(){ | |
System.out.println("Parent.doStuff"); | |
super.doStuff(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment