Olete.in
Articles
Mock Tests
π§ͺ 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
True
False
Error
None of These
2. This language is influenced by Groovy
Ruby
Kotlin
Go
None of these
3. Java is required to install Groovy
Yes
No
Error
None of These
4. What is the command to check java version
java -version
java -v
java β β version
None of These
5. What is the command to check groovy version
groovy βversion
groovy -v
Both A & B
All of the above
6. What is the command to install groovy on Mac OS using Homebrew
brew install groovy
brew get groovy
brew add groovy
None of These
7. Groovy was designed by James Strachan
Yes
No
Error
None of the above
8. Groovy code is compiled to JVM byte code
True
False
Error
All of the above
9. Groovy is both a static and dynamic language
True
False
Error
All of the above
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
True
False
Error
None of the above
11. Guess the output You can run and check the code here β https://groovy-playground.appspot.com/ def match = "Groovy" =~ "Groovy" println match[0]
Groovy
1
null
exception
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" }
Groovy
123
nul
l 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" }
No match found
oo
exception
None of These
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
True
False
Error
None of These
15. An abstract class is declared with a keyword abstract e.g. abstract class Car{ }
True
False
Error
None of these
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();
True
False
Error
None of these
17. An abstract class cannot be instantiated. (Objects cannot be created for an abstract class)
True
False
Error
None of These
18. An abstract class can have final method static method constructors
True
False
Error
None of These
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.
True
False
Error
None of These
20. The body for abstract methods inside an abstract class has to be provided in its child class
True
False
Error
None of These
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() } }
Name of the fruit is Apple
Exception
null
None of the above
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() } }
Name of the fruit is Apple
Exception
null
None of These
23. Guess the output File myFile = new File("file1.txt") myFile.write("This is Line 1") println myFile.text
A file will be created named file1.txt and the text will be written in the file. The text will also get printed on the console
A blank file will get created
exception
None of these
24. // << left shift operator Guess the output File myFile = new File("file1.txt") myFile << "This is Line 1"
File with name file1.txt will get created and data will be written in the file
An empty file will get created
Exception
None of These
25. Guess the output File myFile = new File("file1.txt") myFile << "This is Line 1" myFile.text = "This is Line 2" println myFile.text
This is Line 1 This is Line 2
This is Line 1
This is Line 2
None of these
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
This is Line 1 This is Line 2
This is Line 2
This is Line 1
None of these
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()
//size of the file in bytes
False
true
None of these
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
No change
A new file named file2.txt will get created and data will be copied from file1.txt
exception
A new blank file will get created
29. Guess the output File myFile = new File("file1.txt") myFile.write("This is Line 1") myFile.bytes = []
Will empty the file file1.txt
no change
exception
None of the above
30. // Renaming file Guess the output File myFile = new File("file1.txt") myFile.write("This is Line 1") myFile.renameTo(new File("newfile.txt"))
file1.txt will get renamed to newfile.txt
A new file named newfile.txt will get created
both (a) and (b)
None of these
Submit