[オブジェクト指向と情報処理試験 -2001年 秋-]
(基本:午後・問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 [ a ]; } public boolean colorIs(String color) { return [ b ]; } public String toString() { return code + ", " + size + ", " + color; } } class Slacks extends Pants { Slacks(String code, int size, String color) { super(code, size, color); } } class Jeans extens Pants { boolean buttonFront; Jeans(String code, int size, String color, boolean buttonFront) { [ c ]; this.buttonFront = buttonFront; } public String toString() { return [ d ]; } }
設問 プログラムの [ ] に入れる正しい答えを、解答群の中から選べ。
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")