Apache%20Groovy/Groovy.%20MCQ Sample Test,Sample questions

Question:
  This language is influenced by Groovy

1.Ruby

2.Kotlin

3.Go

4.None of these

Posted Date:-2022-11-17 11:44:36


Question:
 Groovy is both a static and dynamic language

1.True

2.False

3.Error

4.All of the above

Posted Date:-2022-11-17 12:00:10


Question:
 Groovy is Java-syntax-compatible language

1.True

2.False

3.Error

4.None of These

Posted Date:-2022-11-17 11:40:28


Question:
// << left shift operator

Guess the output

File myFile = new File("file1.txt")
myFile << "This is Line 1"

1.File with name file1.txt will get created and data will be written in the file

2.An empty file will get created

3.Exception

4.None of These

Posted Date:-2022-11-17 12:40:15


Question:
// Renaming file

Guess the output

File myFile = new File("file1.txt")
myFile.write("This is Line 1")
myFile.renameTo(new File("newfile.txt"))

1.file1.txt will get renamed to newfile.txt

2.A new file named newfile.txt will get created

3.both (a) and (b)

4.None of these

Posted Date:-2022-11-17 12:55:31


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

1.This is Line 1 This is Line 2

2.This is Line 2

3.This is Line 1

4.None of these

Posted Date:-2022-11-17 12:42:52


Question:
A regular expression, regex or regexp is a sequence of characters that define a search pattern.

Patterns used to find substrings in a text

1.True

2.False

3.Error

4.None of the above

Posted Date:-2022-11-17 12:02:08


Question:
An abstract class can have

final method

static method

constructors

1.True

2.False

3.Error

4.None of These

Posted Date:-2022-11-17 12:22:34


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

1.True

2.False

3.Error

4.None of These

Posted Date:-2022-11-17 12:21:52


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

1.True

2.False

3.Error

4.None of these

Posted Date:-2022-11-17 12:21:13


Question:
An abstract class is declared with a keyword abstract

e.g.

abstract class Car{
}

1.True

2.False

3.Error

4.None of these

Posted Date:-2022-11-17 12:20:19


Question:
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

1.True

2.False

3.Error

4.None of These

Posted Date:-2022-11-17 12:17:50


Question:
Groovy code is compiled to JVM byte code

1.True

2.False

3.Error

4.All of the above

Posted Date:-2022-11-17 11:59:01


Question:
Groovy was designed by James Strachan

1.Yes

2.No

3.Error

4.None of the above

Posted Date:-2022-11-17 11:58:29


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

1.Name of the fruit is Apple

2.Exception

3.null

4.None of the above

Posted Date:-2022-11-17 12:29:14


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

1.Name of the fruit is Apple

2.Exception

3.null

4.None of These

Posted Date:-2022-11-17 12:31:38


Question:
Guess the output

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

1.This is Line 1 This is Line 2

2.This is Line 1

3.This is Line 2

4.None of these

Posted Date:-2022-11-17 12:41:30


Question:
Guess the output

File myFile = new File("file1.txt")
myFile.write("This is Line 1")

File newFile = new File("file2.txt")

newFile << myFile.text

1.No change

2.A new file named file2.txt will get created and data will be copied from file1.txt

3.exception

4.A new blank file will get created

Posted Date:-2022-11-17 12:53:27


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

1.//size of the file in bytes

2.False

3.true

4.None of these

Posted Date:-2022-11-17 12:52:28


Question:
Guess the output

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

1.Will empty the file file1.txt

2.no change

3. exception

4.None of the above

Posted Date:-2022-11-17 12:54:42


Question:
Guess the output

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

1.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

2.A blank file will get created

3.exception

4.None of these

Posted Date:-2022-11-17 12:36:47


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

1.Groovy

2.123

3.nul

4.l No match found

Posted Date:-2022-11-17 12:04:34


Question:
Guess the output

You can run and check the code here – https://groovy-playground.appspot.com/

def match = "Groovy" =~ "Groovy"
println match[0]

1.Groovy

2.1

3.null

4.exception

Posted Date:-2022-11-17 12:03:07


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

1.No match found

2.oo

3.exception

4.None of These

Posted Date:-2022-11-17 12:06:31


Question:
Java is required to install Groovy

1.Yes

2. No

3.Error

4.None of These

Posted Date:-2022-11-17 11:45:23


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

1.True

2.False

3.Error

4.None of These

Posted Date:-2022-11-17 12:23:51


Question:
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.

1.True

2.False

3.Error

4.None of These

Posted Date:-2022-11-17 12:23:18


Question:
What is the command to check groovy version

1.groovy –version

2.groovy -v

3.Both A & B

4.All of the above

Posted Date:-2022-11-17 11:48:43


Question:
What is the command to check java version

1.java -version

2.java -v

3.java – – version

4.None of These

Posted Date:-2022-11-17 11:46:50


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

1.brew install groovy

2.brew get groovy

3.brew add groovy

4.None of These

Posted Date:-2022-11-17 11:49:38


More MCQS

  1. Groovy MCQ
  2. Groovy. MCQ
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!