0
このコードは、return文でオーバーライドされていません。そして、20が出力されます、なぜそれが起こっているのですか?これについての説明は参考になります。Java:return文でのメソッドのオーバーライド
class Rectangle {
public int area(int length, int width){
return length*width;
}
}
class Square extends Rectangle{
public int area(long length, long width){
return (int) Math.pow(length, 2);
}
}
public class JavaApplication36 {
public static void main(String[] args) {
Square r = new Square();
System.out.println(r.area(5, 4));
}
}
intを使用し、longを使用するため、メソッドをオーバーライドしませんでした。あなたの値はintです。 intを使用するようにメソッドのシグネチャを変更します。 –