Skip to content

Instantly share code, notes, and snippets.

@rajeevprasanna
Created January 19, 2014 02:55
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/8499902 to your computer and use it in GitHub Desktop.
Save rajeevprasanna/8499902 to your computer and use it in GitHub Desktop.
code reuse example
package inheritanceIsaAndHasA.codeReuseExample;
public class CodeReuseExampleTest {
public static void main(String[] args) {
PlayerPiece shape = new PlayerPiece();
shape.displayShape();
shape.movePiece();
}
}
package inheritanceIsaAndHasA.codeReuseExample;
public class GameShape {
public void displayShape() {
System.out.println("displaying shape");
}
// more code
}
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