Scala framework-Scala Multiple/Choice Questions Set 2 Sample Test,Sample questions

Question:
    
    def datatype(x:Float){
        println("The parameter is of Float data type")    
    } 
    
    def datatype(x:Char){
        println("The parameter is of Character data type")    
    }
    
    def datatype(x: Boolean){
        println("The parameter is of Boolean data type")    
    }
    
    def main(args: Array[String]) {
        
        datatype(4.0f)
    }
}

1.The parameter is of Boolean data type

2.The parameter is of Integer data type

3.The parameter is of Character data type

4.The parameter is of Float data type


Question:
 2-D structures in Scala can be looped using -

1.Nested Loop

2.Structure

3.Collection iteration

4.None of these


Question:
 Output of the following block of code -

for(i <- 1 to 2){
    for(j <- 1 to 2)
        print("(" + i + "," + j + ")	")
}

1.(1,1) (1,1) (1,1) (1,1)

2.(1,1) (1,2) (2,1) (2,2)

3.(1,1) (2,2) (1,1) (2,2)

4.None of these


Question:
 The break statement in Scala is imported using -

1.import scala.util.control._

2.import scala.break

3.import control

4.None of these


Question:
Array in Scala is -

1.A primary data type

2.Stream of data from I/O

3.Linear data structure with a fixed number of elements

4.All of the above


Question:
Can Lambda expressions be used on collections in Scala?

1.Yes

2.No

3.Error

4.None of These


Question:
Can there be multiple counters in a for loop in Scala?

1.Yes

2.No

3.Error

4.None of These


Question:
Can you alter the sequence of parameter passing?

1.Yes

2.No

3.Error

4.None of these


Question:
Closures in Scala are -

1.Functions that return multiple values

2.Functions that can accept variable arguments

3.Functions that use a value from outside of the function's body

4.None of the above


Question:
Conditional statement in Scala executes a block of code based on some conditional value?

1.True

2.False

3.Error

4.None of These


Question:
Correct syntax for creating an array in Scala -

1.var array_name : Array[data_type] = new Array[data_type(size)

2.var array_name: Array[data_tpye] = new Array(size)

3.var array_name = Array(element1, elmenet2, element3, ...)

4.All of the above


Question:
How to create a mutable array in Scala?

1.Initializing using the var keyword

2.Using arrayBuffer

3.Adding mutable before initialization

4.All of the above


Question:
Ignored variables are used to -

1.Create variables without using names

2.Create blank value variable

3.Both A and B

4.None of these


Question:
Is array mutable in Scala?

1.Yes

2.No

3.Error

4.None of these


Question:
Lambda expression stores the value of -

1.Variable

2.Constant

3.Function

4.None of These


Question:
List in Scala is -

1.Primary data structure

2.The collection that stores data as a string

3.A collection that stores data in the form of a linked-list

4.None of these


Question:
Method overloading in Scala is?

1.Creating multiple methods performing the same task

2.Redefining methods in different ways under the same name

3.Creating methods differently

4.All of these


Question:
Method used to check if a list is empty in Scala -

1.list.isEmpty

2.list.isNull

3.list.empty

4.None of These


Question:
Method used to get the length of array in Scala -

1.Array.len

2.length(arr)

3.arr.size

4.sizeof(arr)


Question:
Methods which can be used to remove/ delete users from arrayBuffer in Scala?

1.arrayBuffer.remove()

2.arrayBuffer.delete()

3.arrayBuffer.push()

4.All of the above


Question:
Recursion function is -

1.A function that calls itself multiple times

2.Has a loop statement

3.All of these

4.None of These


Question:
Tail recursion in Scala is -

1.Initiated from last

2.Initiated from the first call

3.both (a) and (b)

4.None of These


Question:
The default parameters are used when -

1.No parameter is passed

2.The extra parameter is passed

3.Always when the function is called

4.None of These


Question:
The do-while loop in Scala is -

1.Iteration control Loop

2.Entry control loop

3.Exit control loop

4.None of These


Question:
The following code statement will -

import java.util._

1.import _ method from util library

2.Error

3.Import all methods from java.util library

4.None of these


Question:
The for loop in Scala is -

1.Iteration control loop

2.Entry control loop

3.Exit control loop

4.None of These


Question:
The output of the code block of code is -

var myNumber = 5 ;

if(myNumber > 20)
    print("A");
else if(myNumber > 15)
    print("B");
else
    print("C");

1.A

2.B

3.C

4.None of These


Question:
The output of the following block of code is -

class Student{ 
    var roll = 43; 
    
    def printTotal(){
        var totalMarks = 500
        println(roll)
    }
} 

object MyClass{
	def main(args:Array[String]) {
	    var s1 = new Student
	    println(s1.totalMarks)
	}
}

1.500

2.300

3.Error

4.None of these


Question:
The output of the following block of code is -

object Demo {
    def sub( a:Int, b:Int ) = {
        println( (a-b) );
    }
    def main(args: Array[String]) {
        sub(b = 5, a = 7);
    }
}

1.-2

2.2

3.Error

4.None of these


Question:
The output of the following block of code is -

object Demo {
    def welcome( a: Int = 54, b: Int = 21 ){
        println(a + b);
    }
    def main(args: Array[String]) {
        welcome(5);
    }
}

1.75

2.59

3.26

4.10


Question:
The output of the following block of code is -

var myVar = 12; 

print(myVar);

while(myVar <= 10){
    print("*");
    myVar += 2;
}

1.12

2.12****

3.12*

4.None of These


Question:
The output of the following block of code will be -

object myObject {

    var multiplier = 5;
    
    def main(args: Array[String]) {
        println(calculator(45));
    }
    
    val calculator = (i:Int) => i * multiplier;
}

1.45

2.5

3.Error

4.225


Question:
The output of the following code is -

object MyClass{
	def main(args:Array[String]) {
	    var a = 43
	    a += 4 
	    a -= 3
	    println(a)
	} 
}

1.43

2.44

3.45

4.None of these


Question:
To create a loop breakable in Scala, do we need to enclose it?

1.break

2.loop.breakable

3.breaks

4.None of these


Question:
Unit value in Scala is -

1.Used as a return statement when no value is returned to it.

2.The function automatically returns a unit value when no value is returned.

3.Returned using Unit keyword

4.All of these


Question:
Ways to define a composite function in Scala are -

1.Compose keyword

2.andthen keyword

3.Passing method to another method

4.All of the above


Question:
What are expressions in Scala?

1.Line of code that compiles to a value

2.Code block without semicolon

3.Line of code containing = sign

4.None of these


Question:
What is the chopping of string -

1.Divide the string into two equal halves

2.Strip off new line characters

3.Extract substring from a given index

4.None of these


Question:
What is the maximum number of parameters a method can accept?

1.32

2.64

3.128

4.255


Question:
What is the output of the following block of code -

object myObject { 
	def main(args: Array[String]) { 
		println((  div(mul(452)) ))
	} 
	
	val mul = (a: Int)=> { 
		a * 100
	} 
	
	val div = (a: Int) =>{ 
		a / 500
	} 
}

1.45200

2.0

3.90

4.Error


Question:
Which is valid to method to increase value of variable by one?

1.a++

2.++a

3.a += 1

4.All of these


Question:
Which of these can be solved using recursion?

1.Factorial

2.Fibonacci

3.Both A and B

4.None of these


Question:
Which of these is not a conditional statement in Scala?

1.if statement

2.if-else statement

3.This statement

4.None of these


Question:
Which of these parts of the declaration are not required in the case of parameter less methods?

1.def keyword

2.Return type

3.Parenthesis ()

4.All of the above


Question:
Which of these ways of invoking a method are valid in Scala?

1.Using . operator

2.Using direct name call by other methods of the same class

3.Using inheritance

4.All of the above


Question:
Which Scala keyword is used to create an array?

1.Arr

2.array

3.Array

4.All of the above


Question:
Which statement in Scala is used to create a tail-recursive function -

1.@newtailRec

2. @tailRecFunc

3.@tailRec

4.@tailrec


Question:
Which syntax to pass the variable argument to function in Scala?

1.(int a, int b, int c, ….)

2.(a : Int, b : Int, c:Int, …)

3.(args: String*)

4.None of these


Question:
Wildcard patterns (_) is used to -

1.Create variables

2.Create new unmatched patterns

3.Match the unmatched case

4.None of these


Question:
Yield in Scala is used to -

1.Returns the resultant value of for loop

2.Stores a variable at each for loop iteration

3.Used with for loop

4.All of the above


More MCQS

  1. Scala Multiple Choice Questions
  2. Scala Multiple-Choice Questions Set 1
  3. Scala Multiple-Choice Questions Set 2
Search
Olete Team
Online Exam TestTop Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on Online Exam Testwebsite 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!