[Training Video - 4] [Groovy] Function in detail
Employee.log=log Employee e1 = new Employee() Employee e2 = new Employee() e1.name = "A" e1.salary = 100 e2.name = "B" e2.salary = 200 e1.printName() e2.printName() def newSalary = e1.increaseSalary(100) log.info "New salary of A is $newSalary" e2.increaseSalary(100) log.info "Salary of $e1.name is $e1.salary" log.info "Salary of $e2.name is $e2.salary" class Employee { def static log def name def salary public void printName(){ log.info name } public int increaseSalary(amt){ salary = salary+amt return salary } }
Run Result:
Tue Oct 06 19:24:47 CST 2015:INFO:A Tue Oct 06 19:24:47 CST 2015:INFO:B Tue Oct 06 19:24:47 CST 2015:INFO:New salary of A is 200 Tue Oct 06 19:24:47 CST 2015:INFO:Salary of A is 200 Tue Oct 06 19:24:47 CST 2015:INFO:Salary of B is 300