Groovy Quiz 15 | Methods Reference video | Groovy Playground 1 Point for every correct answer | Let’s Get Started 1. Guess the output def sayHello(){ println "Hello..." } Hello… No output Exception 2. //calling function def sayHello(){ println "Hello..." } sayHello() Hello… No output Exception 3. //calling function with parameter def sayHello(String name){ println "Hello "+name } sayHello("Raghav") Hello name Hello Raghav Exception 4. //parameterized function OR function with parameter def sum(int num1, int num2){ println "Sum is "+(num1+num2) } sum(2,5) Exception Sum is 7 Sum is 7 (num1+num2) 5. //calling a parameterized function without parameters def sum(int num1, int num2){ println "Sum is "+(num1+num2) } sum() Sum is Exception 6. //Running with default parameters def sum(int num1=10, int num2=20){ println "Sum is "+(num1+num2) } sum() Exception Sum is 30 Sum is 10+20 7. def sum(int num1, int num2=20){ println "Sum is "+(num1+num2) } sum(5) Sum is 20 Sum is 25 Exception 8. //method return def sub(int num1, int num2){ def result = num1 - num2 return result } print sub(20, 10) 10 result Exception Loading … 12 Share this:TwitterFacebookLinkedIn Related