東京理科大学 infoserv[更新日]2001.11.05


問8

 次の Java プログラムの説明及びプログラムを読んで,設問に答えよ。

〔プログラムの説明〕

プログラムは,ある衣料品小売業 A 社の在庫管理システムで使用するクラスと そのテスト用クラスからなる。 現在 A 社で取り扱う商品はスラックス(Slacks)とジーンズ(Jeans)であり, 両方に共通な属性である品番(code), サイズ(size)及び色(color)は 抽象クラス Pants で定義する。 サイズ及び色については,それぞれの属性値が引数の値と等しいかどうかを 判定するメソッドとして sizeIs 及び colorIs を定義する。

ジーンズ(Jeans)は,打ち合いがボタン留めであるかファスナー留めで あるかを示す属性(buttonFront)をもつ。

テスト用クラスのメソッド main を実行すると,次の実行結果を得る。

S1, 31, Black
S2, 31, Black
J1, 32, Black, zipper
J2, 34, Blue, button
true
true
false
false

図 実行結果

〔プログラム〕

public class TestPants { // テスト用クラス
   public static void main(String[] args) {
      Pants[] pants = {
         new Slacks("S1", 31, "Black"),
         new Slacks("S2", 31, "Black"),
         new Jeans("J1", 32, "Black", false),
         new Jeans("J2", 34, "Blue", true),
      };
      String black = new String("Black");
      for (int i = 0; i < pants.length; i++) {
         System.out.println(pants[i]);
      }
      System.out.println(pants[0].sizeIs(31));
      System.out.println(pants[1].colorIs(black));
      System.out.println(pants[2].sizeIs(30));
      System.out.println(pants[3].colorIs(black));
   }
}

abstract class Pants {
   String code;
   int size;
   String color;
   Pants(String code, int size, String color) {
      this.code = code;
      this.size = size;
      this.color = color;
   }
   public boolean sizeIs(int size) {
      return ;
   }
   public boolean colorIs(String color) {
      return ; 
   }
   public String toString() {                   
      return code + ", " + size + ", " + color;
   }
}

class Slacks extends Pants {
   Slacks(String code, int size, String color) {
      super(code, size, color);
   }
}
class Jeans extends Pants {
   boolean buttonFront;
   Jeans(String code, int size, String color, boolean buttonFront) {
      ;
      this.buttonFront = buttonFront;
   }
   public String toString() {                   
      return ;
   }
}

設問 プログラム中の に入れる正しい答えを,解答群の中から選べ。

a,b に関する解答群

ア this.size = size       イ this.size == size

ウ this.size.equals(size)    エ this.color = color

オ this.color == color     カ this.color.equals(color)

c に関する解答群

ア super()

イ super(buttonFront)

ウ super(code, size, color)

エ super(code, size, color, buttonFront)

d に関する解答群

ア code + ", " + size + ", " + color

イ code + ", " + size + ", " + color + ", " + buttonFront

ウ super.toString() + ", " + buttonFront

エ super.toString() + ", " + (buttonFront ? "button" : "zipper")


東京理科大学 infoserv 戻る 次頁:問09