πŸ§ͺ Apache Groovy MCQ Quiz Hub

Groovy. MCQ

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

Groovy is Java-syntax-compatible language





βœ… Correct Answer: 1

This language is influenced by Groovy





βœ… Correct Answer: 3

Java is required to install Groovy





βœ… Correct Answer: 1

What is the command to check java version





βœ… Correct Answer: 1

What is the command to check groovy version





βœ… Correct Answer: 3

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





βœ… Correct Answer: 1

Groovy was designed by James Strachan





βœ… Correct Answer: 1

Groovy code is compiled to JVM byte code





βœ… Correct Answer: 1

Groovy is both a static and dynamic language





βœ… Correct Answer: 1

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





βœ… Correct Answer: 1

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





βœ… Correct Answer: 1

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" }





βœ… Correct Answer: 4

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" }





βœ… Correct Answer: 2

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





βœ… Correct Answer: 1

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





βœ… Correct Answer: 1

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();





βœ… Correct Answer: 2

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





βœ… Correct Answer: 1

An abstract class can have final method static method constructors





βœ… Correct Answer: 1

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.





βœ… Correct Answer: 1

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





βœ… Correct Answer: 1

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() } }





βœ… Correct Answer: 1

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() } }





βœ… Correct Answer: 1

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





βœ… Correct Answer: 1

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





βœ… Correct Answer: 1

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





βœ… Correct Answer: 3

// 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





βœ… Correct Answer: 2

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()





βœ… Correct Answer: 1

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





βœ… Correct Answer: 2

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





βœ… Correct Answer: 1

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





βœ… Correct Answer: 2