我相当确定overLY仅指的是方法.它是否也可以引用数据类型?我知道在Derived的一个实例中,x将= 1而不是0.但这是否被认为是最重要的?
class Base {
int x = 0 ;
}
class Derived extends Base {
int x = 1 ;
}
Run Code Online (Sandbox Code Playgroud) 我认为我的程序正在跳过我的while循环,但老实说我不确定究竟发生了什么.该函数应该通过找到GCD然后将分子和分母除以该数来减少分数.
class Rational {
private int numerator, denominator;
//Constructor
public Rational (int num, int den) {
numerator = num;
denominator = den;
}
//Method for multiplying fractions
public Rational times (Rational that) {
Rational x = new Rational (this.numerator*that.numerator, this.denominator*that.denominator);
x = x.reduce();
return x;
}
//Method for displaying fractions as strings
public String toString() {
return new String(numerator+"/"+denominator);
}
//Method for adding fractions
public Rational plus(Rational that) {
Rational x = new Rational ((this.numerator*that.denominator)+(that.numerator*this.denominator),
this.denominator*that.denominator);
//x = x.reduce();
return …Run Code Online (Sandbox Code Playgroud)