★★ Java の宿題ここで答えます Part 52 ★★
■ このスレッドは過去ログ倉庫に格納されています
0097デフォルトの名無しさん
2005/06/28(火) 07:16:23class Fraction extends Number {
private int num;
private int denom;
public Fraction(int n, int d) {
num = n;
denom = d;
}
public String toString() { 2.// "Comment out" the toString method in class Fraction
return num + " / " + denom;
}
// Methods that are declared abstract in Number
public double doubleValue() { return (double) num / (double) denom; } // "Comment out" one of the method declarations for class Fraction
public float floatValue() { return (float) doubleValue(); }
public int intValue() { return num / denom; }
public long longValue() { return intValue(); }
public short shortValue() { return (short) intValue(); }
}
大学で出された問題です。
上のコードで、class Fractionのmethod declarationの1つどれか"comment out”
してtoString methodも同じように"comment out”する。それをした後ででるエラーについて説明しろ
という問題なのですが。。。 エラーはclass Fractionのheaderの所に”class fraction should
be declared abstract,it does not define the floatValue() in java.lang.Number"
というエラーが出ます。ちなみに、methodはfloatValue()のラインをcommentしました。マル投げすいません、どなたか教えてください。
■ このスレッドは過去ログ倉庫に格納されています