Computer scienceProgramming languagesKotlinObject-oriented programmingClass hierarchy

Abstract classes

Abstraction forger

Report a typo

Construct an abstract class called Employee with the following characteristics:

  • A primary constructor that accepts two String parameters: name and surname.
  • An abstract Int property named age.
  • An abstract function named doWork.
  • A concrete function named fullName that returns the employee’s full name consisting of their name and surname separated by a single space.

Sample Input 1:

Yassin
Ahmed

Sample Output 1:

My name is: Yassin Ahmed
I am working!
Write a program in Kotlin
// Write your solution here

// DO NOT change the code below
class Worker(name: String, surname: String) : Employee(name, surname) {
override val age = 40

override fun doWork() {
println("I am working!")
}
}

fun main() {
val name = readln()
val surname = readln()

val worker = Worker(name, surname)

println("My name is: ${worker.fullName()}")
worker.doWork()
}
___

Create a free account to access the full topic