我正在尝试测试我的抽象类,但是当我从测试类调用方法时遇到了问题。自从我使用 Java 以来已经有一段时间了,我以前没有使用过抽象类。任何关于我哪里出错的指示将不胜感激。谢谢。
抽象类
public abstract class RationalNumbers {
public int numerator, denominator, temp;
public void setNumerator(int n) {
numerator = n;
}
public void setDenominator(int d) {
denominator = d;
}
public int getNumerator() {
return numerator;
}
public int getDenominator() {
return denominator;
}
public int add() {
temp = numerator + denominator;
return temp;
}
public int subtract() {
temp = numerator - denominator;
return temp;
}
public int multiply() {
temp = numerator * denominator;
return temp;
}
public int divide() {
temp = numerator / denominator;
return temp;
}
public boolean isEqual() {
boolean isEqual;
if (numerator == denominator) {
isEqual = true;
} else {
isEqual = false;
}
return isEqual;
}
}
测试类
public class testClass extends RationalNumbers {
public static void main(String[] args) {
setNumerator(5);
setDenominator(10);
System.out.println("Equal: " + isEqual());
System.out.println("Numerator: " + getNumerator());
// etc...
}
}