Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. public abstract class Tool {
  2.  
  3. private double durability;
  4.  
  5. public double getDurability() {
  6. return durability;
  7. }
  8.  
  9. public void setDurability(double durability) {
  10. this.durability = durability;
  11. }
  12. }
  13.  
  14. public class Axe extends Tool {
  15.  
  16. public void chop() {
  17. //chop some wood
  18. }
  19. }
  20.  
  21. Tool tool = new Axe();
  22.  
  23. ((Axe)tool).chop();
  24.  
  25. if (tool instanceof Axe) {
  26. ((Axe)tool).chop();
  27. }
  28.  
  29. abstract class Tool {
  30.  
  31. private double durability;
  32.  
  33. public double getDurability() {
  34. return durability;
  35. }
  36.  
  37. public void setDurability(double durability) {
  38. this.durability = durability;
  39. }
  40.  
  41. public void work(){
  42.  
  43. }
  44. }
  45.  
  46.  
  47.  
  48.  
  49. class Axe extends Tool {
  50.  
  51. @Override
  52. public void work() {
  53. this.chop();
  54. }
  55.  
  56. public void chop() {
  57. //chop some wood
  58. }
  59. }
  60.  
  61. Axe axe = (Axe) tool;
  62. axe.chop();
  63.  
  64. if (tool instanceof Axe){
  65. Axe axe = (Axe) tool;
  66. axe.chop();
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement