Override Method - Java Quiz Question


Define the classes Cube and PowerOf4 such that it overrides the method getValue() and prints the result.

Class used, Input Output
Cube, 2 8
Cube, -17 -4913
PowerOf4, 5 625
PowerOf4, 25 390625



class OverridePowersOperation
{
    public static void main(String s[])
    {
        Square cube = new Cube();
        System.out.println("The cube of 2 is " + cube.getValue(2));
        Square power4 = new PowerOf4();
        System.out.println("The fourth power of 5 is " + power4.getValue(5));

    }



}
class Square
{
    int getValue(int a)
    {
        return a * a ;
    }
}

class Cube extends Square
{
}
class PowerOf4 extends Square
{
}