Olete.in
Articles
Mock Tests
🧪 Scala framework MCQ Quiz Hub
Scala Multiple-Choice Questions Set 2
Choose a topic to test your knowledge and improve your Scala framework skills
1. 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) } }
500
300
Error
None of these
2. Which is valid to method to increase value of variable by one?
a++
++a
a += 1
All of these
3. The output of the following code is - object MyClass{ def main(args:Array[String]) { var a = 43 a += 4 a -= 3 println(a) } }
43
44
45
None of these
4. Ignored variables are used to -
Create variables without using names
Create blank value variable
Both A and B
None of these
5. Wildcard patterns (_) is used to -
Create variables
Create new unmatched patterns
Match the unmatched case
None of these
6. The following code statement will - import java.util._
import _ method from util library
Error
Import all methods from java.util library
None of these
7. What are expressions in Scala?
Line of code that compiles to a value
Code block without semicolon
Line of code containing = sign
None of these
8. Conditional statement in Scala executes a block of code based on some conditional value?
True
False
Error
None of These
9. Which of these is not a conditional statement in Scala?
if statement
if-else statement
This statement
None of these
10. 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");
A
B
C
None of These
11. The do-while loop in Scala is -
Iteration control Loop
Entry control loop
Exit control loop
None of These
12. The for loop in Scala is -
Iteration control loop
Entry control loop
Exit control loop
None of These
13. The output of the following block of code is - var myVar = 12; print(myVar); while(myVar <= 10){ print("*"); myVar += 2; }
12
12****
12*
None of These
14. 2-D structures in Scala can be looped using -
Nested Loop
Structure
Collection iteration
None of these
15. 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,1) (1,2) (2,1) (2,2)
(1,1) (2,2) (1,1) (2,2)
None of these
16. The break statement in Scala is imported using -
import scala.util.control._
import scala.break
import control
None of these
17. Yield in Scala is used to -
Returns the resultant value of for loop
Stores a variable at each for loop iteration
Used with for loop
All of the above
18. Can there be multiple counters in a for loop in Scala?
Yes
No
Error
None of These
19. To create a loop breakable in Scala, do we need to enclose it?
break
loop.breakable
breaks
None of these
20. The default parameters are used when -
No parameter is passed
The extra parameter is passed
Always when the function is called
None of These
21. 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); } }
75
59
26
10
22. Recursion function is -
A function that calls itself multiple times
Has a loop statement
All of these
None of These
23. Which of these can be solved using recursion?
Factorial
Fibonacci
Both A and B
None of these
24. Method overloading in Scala is?
Creating multiple methods performing the same task
Redefining methods in different ways under the same name
Creating methods differently
All of these
25. 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) } }
The parameter is of Boolean data type
The parameter is of Integer data type
The parameter is of Character data type
The parameter is of Float data type
26. Which statement in Scala is used to create a tail-recursive function -
@newtailRec
@tailRecFunc
@tailRec
@tailrec
27. Tail recursion in Scala is -
Initiated from last
Initiated from the first call
both (a) and (b)
None of These
28. What is the maximum number of parameters a method can accept?
32
64
128
255
29. Which syntax to pass the variable argument to function in Scala?
(int a, int b, int c, ….)
(a : Int, b : Int, c:Int, …)
(args: String*)
None of these
30. Can you alter the sequence of parameter passing?
Yes
No
Error
None of these
31. 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); } }
-2
2
Error
None of these
32. Closures in Scala are -
Functions that return multiple values
Functions that can accept variable arguments
Functions that use a value from outside of the function&#039;s body
None of the above
33. 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; }
45
5
Error
225
34. Which of these parts of the declaration are not required in the case of parameter less methods?
def keyword
Return type
Parenthesis ()
All of the above
35. Which of these ways of invoking a method are valid in Scala?
Using . operator
Using direct name call by other methods of the same class
Using inheritance
All of the above
36. Lambda expression stores the value of -
Variable
Constant
Function
None of These
37. Can Lambda expressions be used on collections in Scala?
Yes
No
Error
None of These
38. Ways to define a composite function in Scala are -
Compose keyword
andthen keyword
Passing method to another method
All of the above
39. 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 } }
45200
0
90
Error
40. What is the chopping of string -
Divide the string into two equal halves
Strip off new line characters
Extract substring from a given index
None of these
41. Unit value in Scala is -
Used as a return statement when no value is returned to it.
The function automatically returns a unit value when no value is returned.
Returned using Unit keyword
All of these
42. Array in Scala is -
A primary data type
Stream of data from I/O
Linear data structure with a fixed number of elements
All of the above
43. Which Scala keyword is used to create an array?
Arr
array
Array
All of the above
44. Correct syntax for creating an array in Scala -
var array_name : Array[data_type] = new Array[data_type(size)
var array_name: Array[data_tpye] = new Array(size)
var array_name = Array(element1, elmenet2, element3, ...)
All of the above
45. Is array mutable in Scala?
Yes
No
Error
None of these
46. How to create a mutable array in Scala?
Initializing using the var keyword
Using arrayBuffer
Adding mutable before initialization
All of the above
47. Methods which can be used to remove/ delete users from arrayBuffer in Scala?
arrayBuffer.remove()
arrayBuffer.delete()
arrayBuffer.push()
All of the above
48. Method used to get the length of array in Scala -
Array.len
length(arr)
arr.size
sizeof(arr)
49. List in Scala is -
Primary data structure
The collection that stores data as a string
A collection that stores data in the form of a linked-list
None of these
50. Method used to check if a list is empty in Scala -
list.isEmpty
list.isNull
list.empty
None of These
Submit