package exercise41; public class Ball { private double x; private double y; private double vx; private double vy; private double L; static final private double gravity = 9.80665; public Ball (double vx , double vy) { this.vx = vx; this.vy = vy; this.L = 2.0 * vx * vy / gravity; } public double getX() { return this.x; } public void tictac(double deltaTime) { vy = vy - (gravity * deltaTime); this.x = x + vx * deltaTime; this.y = y + vy * deltaTime; getX(); } public double getL() { return this.L; } }
package exercise41; public class Field { public Field() { } public void simulate(Ball ball) { for (int i = 0; i < 1000; i++) { ball.tictac(0.001); // Ballインスタンスにtictacメッセージを送る } System.out.println("A1: " + ball.getL()); System.out.println("A2: " + ball.getX()); } public static void main(String[]args) { Field f = new Field(); Ball ball = new Ball(13.0,29.0); f.simulate(ball); } }
<質問>
fieldクラスのsimulateメソッドでBallクラスの変数を使用していますが、クラス継承の手順を行っていないのに使用できるのはなぜなのでしょうか
回答1件
あなたの回答
tips
プレビュー