Which lines lead to compilation errors?
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
}

Explanation
Scala requires an override modifier for all members that override a concrete member in a parent class. The modifier is optional if a member implements an abstract member with the same name. The modifier is forbidden if a member does not override or implement some other member in a base class.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Scala quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes