September 2018
Intermediate to advanced
398 pages
9h 43m
English
An abstract class is a class that can have many abstract members. An abstract member defines only a signature for an attribute or a method, without providing any implementation. You cannot instantiate an abstract class: you must create a subclass that implements all the abstract members.
Replace the definition of Shape and Rectangle in the worksheet as follows:
abstract class Shape(val x: Int, val y: Int) { val area: Double def description: String}class Rectangle(x: Int, y: Int, val width: Int, val height: Int) extends Shape(x, y) { val area: Double = width * height def description: String = "Rectangle " + width + " * " + height}
Our class Shape is now abstract. We cannot instantiate a Shape class directly anymore: we have ...
Read now
Unlock full access