【问题标题】:how to access something sent to the super class如何访问发送到超类的东西
【发布时间】:2016-03-25 19:46:06
【问题描述】:
public class BattleEvent extends EventObject {

    private BattleEventType type;
    private BattleOpponent currentOpponent;
    private BattleOpponent winner;
    private Attack attack;
    private Collectible collectible;


    public BattleEvent(Battle battle, BattleEventType type) {
      super(battle);
      this.type=type;
     this.currentOpponent=battle.getMe();
    }

我在另一个类中有 Battleevent 对象我想访问我发送给 eventObject 的战斗我如何访问它?

【问题讨论】:

    标签: java inheritance extends super


    【解决方案1】:

    我想访问我发送给 eventObject 的战斗

    基于super(battle),你应该有一个看起来像

    的构造函数
    public EventObject(Battle battle)
    

    你如何处理那个参数就是“你如何访问它”

    【讨论】:

      【解决方案2】:

      EventObject 需要将其公开为受保护的成员或为其提供访问器(getter 方法)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-21
        • 2010-10-29
        • 1970-01-01
        • 2011-07-08
        相关资源
        最近更新 更多