Created
January 19, 2014 02:55
-
-
Save rajeevprasanna/8499902 to your computer and use it in GitHub Desktop.
code reuse example
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 inheritanceIsaAndHasA.codeReuseExample; | |
public class CodeReuseExampleTest { | |
public static void main(String[] args) { | |
PlayerPiece shape = new PlayerPiece(); | |
shape.displayShape(); | |
shape.movePiece(); | |
} | |
} |
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 inheritanceIsaAndHasA.codeReuseExample; | |
public class GameShape { | |
public void displayShape() { | |
System.out.println("displaying shape"); | |
} | |
// more code | |
} |
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 inheritanceIsaAndHasA.codeReuseExample; | |
public class PlayerPiece extends GameShape { | |
//It avoids code duplication by inheriting super class methods | |
public void movePiece() { | |
System.out.println("moving game piece"); | |
} | |
// more code | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment