Advertisement
karlakmkj

init block

Jan 14th, 2021
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.44 KB | None | 0 0
  1. class Employee(val firstName: String, val lastName: String, val yearsWorked: Int) {
  2.   // Write your code below
  3.   var fullName  = "$firstName $lastName"
  4.  
  5. init{
  6.   if(yearsWorked >1){
  7.     println("$fullName is eligible for a raise!")
  8.   }
  9.   else {
  10.     println("$fullName is not eligible for a raise just yet.")
  11.   }
  12. }
  13.  
  14. }
  15.  
  16. fun main() {
  17.   // Create an instance below 👩🏻‍💼
  18.   var projectManager = Employee("Maria", "Gonzalez", 2)
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement