Calculator

Report a typo

You have an abstract class called Calculator with one abstract method named perform() and a primary constructor that contains two properties:

abstract class Calculator(val left: Int, val right: Int) {
    abstract fun perform(): Int
}

Your task is to create two concrete classes: Add and Multiply, which extend the Calculator abstract class. These classes should implement the perform() method in a way that corresponds to their respective names, performing addition and multiplication operations.

Sample Input 1:

5
11

Sample Output 1:

16
55
Write a program in Kotlin
// Implement class Add

// Implement class Multiply

fun main() {
val left = readln().toInt()
val right = readln().toInt()

println(Add(left, right).perform())
println(Multiply(left, right).perform())
}

Create a free account to access the full topic