/** Removes the axe owned from the player's inventory */ public void removeAxe() { Sys.print("You have lost your " + axe.getName() + "!"); axe = null; }
// 实现Person接口的useAxe方法 public void useAxe() { // 调用axe的chop()方法, // 表明Person对象依赖于axe对象 System.out.println(axe.chop()); System.out.println("age属性值:" + age); }
/** * Adds a specified axe to the player's inventory * * @param a - Specified axe */ public void addAxe(Axe a) { Sys.print("You have obtained a " + a.getName() + "!"); axe = a; }