open class Person(){ var firstName: String var lastName: String init{ this.firstName = "" this.lastName = "" } constructor(fName: String, lName: String):this(){ this.firstName = fName this.lastName = lName } fun getDetails(): String{ return "$firstName\n$lastName" } } class Employee() : Person(){ var empId: Int var salary: Double init{ this.empId = 0 this.salary = 1000.0 } constructor(id: Int, sal: Double):this.super(fname,lname){ this.empId = id this.salary = sal } } fun main(args: Array<String>){ var p1 = Person("Anadi", "Sharma") var e1= Employee(10,1000.0) print(e1.getDetails()) }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more