Assume you have a class Square. This class has an instance variable, side that is protected and of type double. Write the class definition of a subclass of Square called FancySquare that has a method called getDiagonal. The getDiagonal method gets no arguments but returns the value of side multiplied by the square root of two.

LANGUAGE: JAVA

CHALLENGE:

Assume you have a class Square. This class has an instance variable, side that is protected and of type double.

Write the class definition of a subclass of Square called FancySquare that has a method called getDiagonal. The getDiagonal method gets no arguments but returns the value of side multiplied by the square root of two.

SOLUTION:

class FancySquare extends Square {
   double getDiagonal() {
      return side*Math.sqrt(2.0);
   }
}