Questions of Test: Groovy -Beginner Test

1

select the correct defined  groovy closures-

2

Which protocol enables an object to make specific choices that affect its own state or behavior when methods, or messages, are passed to it at runtime?

3

A Closure Defined as-
     square = { it * it }
what will be output for square(7)?

4

what will be result of following closure ?

printMe = { key, value ->
 println key + "=" + value
 }

[ "Apple" : "wu", "Banana" : "burks", "Grape" : "glen" ].each(printMe)

5

what will be output of following code snippet-


Arrays.metaClass.'static'.sort = { a ->    //1
    a[0] = 'ewe'
    a[1] = 'fox'
}

things = ['dog', 'ant', 'bee', 'cat']
Arrays.sort(things)    //2
println things

6

How do we use Safe Navigation Operator (?.) in groovy-

7

which one is correct use of annotations in Groovy-

8

What we need to run Groovy code ?

9

I get errors when trying to run groovy, groovysh or groovyConsole. Whats wrong?

10

Which options are true about Groovy language -