【问题标题】:Passing a Boolean variable to an Array List with String's将布尔变量传递给带有字符串的 Arraylist
【发布时间】:2012-01-02 14:47:44
【问题描述】:

我是否可以在我的抽象类中保存我所有的私有数据类型,以便我以后可以使用保存在我的数组列表中的存储信息(数组列表在不同的类中)。我已经设法存储所有字符串,以前 bur 没有成功使用我的布尔值。我知道数组列表用于引用对象。谢谢

public abstract class Room
{
    private String roomID;
    private boolean ensuite;
    private String guest;
    private String nights;
    private String booked;

    public abstract room (String roomID boolean ensuite)
}

【问题讨论】:

    标签: java arrays constructor boolean abstract


    【解决方案1】:

    这是否完全从您的代码中复制而来?在String roomIdboolean ensuite 之间缺少,。方法声明中也不需要抽象。

    试试这个:

    public abstract class Room
    {
        private String roomID;
        private boolean ensuite;
        private String guest;
        private String nights;
        private String booked;
    
        public Room (String roomID, boolean ensuite)
        {
           this.roomID = roomID;
           this.ensuite = ensuite;
           //so on...
        }
    }
    

    【讨论】:

      【解决方案2】:
      public abstract class Room
      {
          private String roomID;
          private boolean ensuite;
          // ...
      
          public Room(String roomID, boolean ensuite)
          {
            this.roomID = roomID;
            this.ensuite = ensuite;
            // ...
          }
      }
      

      【讨论】:

      • 好的,添加所有这些。命令我应该能够调用 //return Room;这将显示所有正确的信息吗?谢谢
      猜你喜欢
      • 2022-12-31
      • 2016-08-28
      • 1970-01-01
      • 2020-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多