Java - How do this subclass interact with the main class
<p>I'm stuck on a mock exam question. I created a class called <code>Power</code> which allowed a number to be raised to any power.</p>

<p>The third part of the question asks me to create another class <code>BoundedPower</code> which would extend <code>Power</code>. I was given the <code>MAX-X</code> variable (x cannot exceed this value) and told that the <code>BoundedPower</code> class must: behave like the <code>Power</code> class, use a constructor and use the<code>powN</code> method.</p>

<p>My code is below, i am not sure what to do to make the <code>BoundedPower</code> class work.</p>

<pre><code>public class Power {

    private double x = 0;

    Power(double x) {
        this.x = x;
    }

    public double getX() {
        return x;
    }

    public double powN(int n) {

        double result = 1.0;
        for (int i = 0; i &lt; n; i++) {
            result = result * x;
        }
        return result;

    }

    public static void main(String[] args) {

        Power p = new Power(5.0);
        double d = p.powN(3);
        System.out.println(d);
    }

}


public class BoundedPower extends Power {

    public static final double MAX_X = 1000000;

    // invariant: x &lt;= MAX_X

    Power x;

    BoundedPower(double x) {
        super(x);
        // this.x=x; x is private in Power class

    }

    public double powN(int n) {

        if (x.getX() &gt; MAX_X) {

            return 0;
        } else {

            double result = 1.0;
            for (int i = 0; i &lt; n; i++) {
                result = result * getX();
            }
            return result;
        }
    }

    public static void main(String[] args) {

        BoundedPower bp = new BoundedPower(5);
        double test = bp.powN(4);
        System.out.println(test);
    }

}
</code></pre>
