πŸ§ͺ Apache Groovy MCQ Quiz Hub

Groovy. MCQ

Choose a topic to test your knowledge and improve your Apache Groovy skills

1. Groovy is Java-syntax-compatible language




2. This language is influenced by Groovy




3. Java is required to install Groovy




4. What is the command to check java version




5. What is the command to check groovy version




6. What is the command to install groovy on Mac OS using Homebrew




7. Groovy was designed by James Strachan




8. Groovy code is compiled to JVM byte code




9. Groovy is both a static and dynamic language




10. A regular expression, regex or regexp is a sequence of characters that define a search pattern. Patterns used to find substrings in a text




11. Guess the output You can run and check the code here – https://groovy-playground.appspot.com/ def match = "Groovy" =~ "Groovy" println match[0]




12. Guess the output You can run and check the code here – https://groovy-playground.appspot.com/ def match = "Groovy" =~ "123" if(match){ println match[0] }else{ println "No match found" }




13. Guess the output You can run and check the code here – https://groovy-playground.appspot.com/ def match = "Groovy" =~ "o" if(match){ def num=0 while(match){ print match[num] num++ } }else{ println "No match found" }




14. An interface can have only abstract methods whereas An abstract class can have both abstract and non-abstract (concrete) methods non-abstract methods also have body




15. An abstract class is declared with a keyword abstract e.g. abstract class Car{ }




16. An abstract class cannot have non-abstract methods hint abstract methods have only method signature and no body. abstract methods are declared with keyword abstract e.g. public abstract void maxSpeed();




17. An abstract class cannot be instantiated. (Objects cannot be created for an abstract class)




18. An abstract class can have final method static method constructors




19. To use any method or field of an abstract class, it has to be extended in a child class because abstract classes cannot be instantiated.




20. The body for abstract methods inside an abstract class has to be provided in its child class




21. Guess the output class Fruits{ String fruitName String fruitColor def setName(String name){ fruitName = name } def getFruitName(){ println "Name of the fruit is $fruitName" } static void main(args){ println "I am inside main" Fruits apple = new Fruits() apple.setName("Apple") apple.getFruitName() } }




22. Guess the output class Fruits{ String fruitName String fruitColor def setName(String name){ fruitName = name } def getFruitName(){ println "Name of the fruit is $fruitName" } static void main(args){ println "I am inside main" Fruits apple = new Fruits() apple.setName("Apple") apple.getFruitName() } }




23. Guess the output File myFile = new File("file1.txt") myFile.write("This is Line 1") println myFile.text




24. // << left shift operator Guess the output File myFile = new File("file1.txt") myFile << "This is Line 1"




25. Guess the output File myFile = new File("file1.txt") myFile << "This is Line 1" myFile.text = "This is Line 2" println myFile.text




26. // using withWriter Guess the output File myFile = new File("file1.txt") myFile.write("This is line 1") myFile.withWriter { writer -> writer.writeLine("This is Line 2") } println myFile.text




27. Guess the output File myFile = new File("file1.txt") myFile.write("This is Line 1") println myFile.length() println myFile.isFile() println myFile.isDirectory() println myFile.isHidden()




28. Guess the output File myFile = new File("file1.txt") myFile.write("This is Line 1") File newFile = new File("file2.txt") newFile << myFile.text




29. Guess the output File myFile = new File("file1.txt") myFile.write("This is Line 1") myFile.bytes = []




30. // Renaming file Guess the output File myFile = new File("file1.txt") myFile.write("This is Line 1") myFile.renameTo(new File("newfile.txt"))