abstract class Shape {
  def perimeter: Int
  def area: Int
}
class Rectangle(width: Int, height: Int) extends Shape {
  def perimeter = 2 * (width + height) // 1
  override def area = width * height   // 2
}
class Square(width: Int) extends Rectangle(width, width) {
  def perimeter = 4 * width            // 3
  override def area = width * width    // 4
}
Login in to like
Login in to comment