300+ TOP Scala MCQ Questions and Answers Quiz

Scala Multiple Choice Questions

1. Which of the following is not a feature of Scala?

  1. Type inference
  2. Lazy Computation
  3. High order function
  4. None of the above

Answer: D None of the above

Explanation: Some common features of Scala are,

  • It runs on a JVM but the compiler is different.
  • Integrates Features of both Object-Oriented Programming and Functional Programming.
  • Lazy Computation increases performance, the expression evaluates only when its evaluation is required.
  • Immutability: it means the value of data cannot be changed by default.
  • Case Classes and Pattern Matching.
  • Type Interface: It recognizes data type and functions return type itself.
  • Concurrency Control: Scala Provide concurrency control using the actor model.
  • High Order Function: A function that works on another function.

2. Is Java required before installing Scala on the system?

  1. Yes
  2. No

Answer: A Yes

Explanation: Yes. Before you start installing Scala on your machine, you must have Java 1.8 or greater installed on your computer.

3. The semicolon (;) in Scala is –

  1. Necessary, failing to write will not mark the end of line
  2. Not required, it is treated as a character
  3. Optional, end of the line does not require ;
  4. None of these

Answer: C Optional, end of the line does not require ;

Explanation: If the programmer puts a semicolon at the end of the line it’s ok and if no semicolon is present even then too the compiler does not throw any error. Read more: Semicolons in Scala

4. Scala programming language was developed by –

  1. James Gosling
  2. Martin Odersky
  3. Dennis MacAlistair Ritchie
  4. Guido van Rossum

Answer: B Martin Odersky

Explanation: Scala is a programming language developed by Martin Odersky. It came into the market in 2003.

5. What is the paradigm of the Scala programming language?

  1. Object-oriented
  2. Statically Types
  3. Functional
  4. All of the above

Answer: D All of the above

Explanation: Scala is a modern multi-paradigm programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It seamlessly integrates features of object-oriented and functional languages.

6. Scala stands for ___.

  1. Scalable language
  2. Scripted advanced language
  3. Sequential language
  4. None

Answer: A Scalable language

Explanation: Scala stands for Scalable language.

7. The Scala compiler starts executing from –

  1. The first line of code
  2. main() method
  3. main class
  4. End of code

Answer: B main() method

Explanation: The entry point of the flow of code in Scala is the main() method. There is no specific object required, it can be present in any object of the program.

8. Which of the following are not present in Scala?

  1. Closures
  2. Monads
  3. Traits
  4. None

Answer: D None

Explanation: All the above features are present in Scala.

9. The correct syntax for creating Single line comments in Scala is,

  1. //
  2. <!– — >
  3. /* */
  4. %%

Answer: A //

Explanation: // is used to create a single line comment in Scala. /*…*/ is used to create multiline comments in Scala.

10. The correct output of the following code is,

object MyClass {
def main(args: Array[String]) {
var i,j=0
for(i <- 0 to 3){
for(j <- 0 until 2){
if(i + j == 3){
print((i*j)+”\t”)
}
}
}
}
}

  1. 3 3
  2. 2 0
  3. 0 2
  4. 1 1

Answer: B 2 0

Explanation: In a nested loop, we will print values, The first iteration is 2, 1 and the second is 3, 0.

11. Which of these is not a primary data type in Scala –

  1. Integer
  2. String
  3. Array
  4. Char

Answer: C Array

Explanation: Array is not a primary data in Scala.

12. The size of integer data type in Scala is –

  1. 256 bits
  2. 4 bits
  3. 32 bits
  4. 64 bits

Answer: C 32 bits

Explanation: An Integer is a 32-bit value and is central to any numeric representation in Scala.

13. Why is Double better than Float values?

  1. It can store double-precision values providing more accurate data to be stored.
  2. It stores 64 bits values instead of 32 bits from a float.
  3. Float Values are better
  4. Both A and B

Answer: D Both A and B

Explanation: The Double type is more precise than Float type and can store 64 bits, double of the number of bits float can store. Double is more precise and for storing large numbers, we prefer double over float.

14. Which class is the super-class of all classes in Scala?

  1. Ref
  2. AnyRef
  3. Any
  4. AnyVar

Answer: C Any

Explanation: Any is the superclass of all classes, also called the top class. any class is inherited by all classes in Scala.

15. Which type class does not inherit AnyVar?

  1. Char
  2. Int
  3. Float
  4. Pointer

Answer: D Pointer

Explanation: All the other values inherit AnyVar class.

16. The correct output of the below code block is –

object MyClass {
def main(args: Array[String]) {
var a : Float = 454.32138988f
var b : Double = a;

printf(“a = ” + a + “\t b = ” + b)
}
}

  1. a = 454.32138988 b = 454.32138988152344
  2. a = 454.32138 b = 454.3213806152344
  3. a = 454.32138 b = 454.32138
  4. error

Answer: A a = 454.32138988 b = 454.32138988152344

17. Default values of string type when it is not initialized –

  1. 0
  2. Null
  3. None
  4. ” “

Answer: B Null

Explanation: The default value of the string variable is Null.

18. Which type in Scala is a subtype of all types –

  1. Int
  2. Ref
  3. Boolean
  4. Nothing

Answer: D Nothing

Explanation: In Scala, Nothing is treated as the subtype of all types.

19. Statement returned by function when no values are returned in Scala –

  1. No value
  2. Unit
  3. Int
  4. None of these

Answer: B Unit

Explanation: Statement returned by function when no values are returned in Scala is Unit.

20. In Scala, can you return two values?

  1. Yes
  2. No

Answer: A Yes

Explanation: In Scala, Options are used to return two instances.

21. What is the range defined by the below statement –

range(13, 17, 2)
  1. 13 14 15 16 17
  2. 13 14 15 16
  3. 13 15
  4. 13 15 17

Answer: C 13 15

Explanation: The range will exclude the last value and iterate by 2 for each value.

22. Which is not a Scala method for printing text on the screen?

  1. print()
  2. printf()
  3. printl()
  4. println()

Answer: C printl()

Explanation: The printl() is not a valid Scala method. All three above mentioned methods are used for printing.

23. What is the output of following code?

val i = 43
i = 231
printf(i)

  1. 231
  2. 43
  3. 0
  4. Error

Answer: D Error

Explanation: The val keyword defines immutable values in Scala. [Read more: Scala Literal, Variables and Data Type]

24. Literals in Scala are ___.

  1. Name of the variables
  2. A literal is a value that can be assigned to a variable
  3. The type of the values
  4. None of these

Answer: B A literal is a value that can be assigned to a variable

Explanation: Any constant value which can be assigned to the variable is called as literal

25. Based on Type Casting, which of these conversions is lossy or invalid?

  1. Character -> Float
  2. Float -> Long
  3. Short -> Integer
  4. Integer -> Double

Answer: B Float -> Long

Explanation: Float – > Long is not a valid type casting. [Refer diagram given here: Scala Type Casting]

26. Which type of typecasting is done by the compiler?

  1. Implicit Conversion
  2. Explicit Conversion
  3. Instance conversion
  4. None of these

Answer: A Implicit Conversion

Explanation: In the implicit type casting of type – the compiler itself cast the type of the value/variable.

27. Explicit Conversion is –

  1. Done by the compiler itself
  2. Defined by the user
  3. Both A and B
  4. None of the above

Answer: B Defined by the user

Explanation: The explicit type conversion is a user-defined type conversion i.e., the user/programmer will decide the final data type of the value/variable.

28. The getClass() method is used to –

  1. Extract the class of the given number
  2. Extract the value of the variable
  3. Extract the memory location of the variable
  4. All of the Above

Answer: A Extract the class of the given number

Explanation: The getClass() method is used to return the class of the given number.

29. Converting Character to Integer will return –

  1. Error
  2. Random integer value
  3. ASCII value of the character
  4. None of the above

Answer: C ASCII value of the character

Explanation: Converting a character to integer will return the ASCII value of the character.

30. Which Scala keyword is used to initialize a variable?

  1. int
  2. var
  3. value
  4. None

Answer: B var

Explanation: Scala variables are created using the var keyword.

31. Lazy initialization is –

  1. Creating variables using the lazy keyword
  2. Done only on immutable variables
  3. Calculated at its first access
  4. All of the above

Answer: D All of the above

Explanation: Lazy initialization variables are those variables that are calculated when the first time they are accessed. Scala mutable variables cannot be lazy.

32. The total number of keywords in Scala are –

  1. 45
  2. 34
  3. 39
  4. 52

Answer: C 39

Explanation: There are in total 39 keywords present in Scala. [Learn more: Scala Keywords]

33. Which of these is not a keyword in Scala?

  1. int
  2. var
  3. forsome
  4. package

Answer: A int

Explanation: “int” is not a Scala keyword.

34. Using a keyword as a value will lead to –

  1. Error
  2. Compile with the NULL value
  3. Warning
  4. None of these

Answer: A Error

Explanation: The compiler will throw an error if we try to use keywords as identifiers.

35. Is ‘sealed’ a keyword in Scala –

  1. Yes
  2. No

Answer: A Yes

Explanation: Yes, the sealed is a keyword in Scala.

36. Identifiers in Scala are names given to –

  1. Classes or objects
  2. Methods
  3. Objects
  4. All of these

Answer: D All of these

Explanation: Identifiers in a programming language are the names given to a class, method, variable, or object to identify them in the program.

37. Which of these is not a type of identifier –

  1. Alphanumeric identifier
  2. Operator identifier
  3. Literal identifier
  4. Value identifier

Answer: D Value identifier

Explanation: In Scala, we have 4 different types of identifiers defined. They are:

  1. Alphanumeric Identifiers
  2. Operator Identifiers
  3. Mixed Identifiers
  4. Literal Identifiers

38. Is the following identifier valid?

12Scala_3
  1. Yes
  2. No

Answer: B No

Explanation: “12Scala_3” is not a valid identifier. The identifiers must be started either an alphabet or an underscore (_).

39. Literal Identifier is –

  1. String literal used as an identifier in Scala
  2. Value literal used as an identifier in Scala
  3. Numeric literal used as an identifier in Scala
  4. None

Answer: A String literal used as an identifier in Scala

40. The correct output of the following code is –

object myObject {
def main(args: Array[String]) {
var _value1 = 54
var 3value_2 = 65

println(“The sum of two values is ” + (_value1 + value_2))
}
}

  1. 54
  2. Error
  3. 119
  4. 65

Answer: B Error

Explanation: The second variable is 3value_2 which is not an valid identifier and in the expression, we are using value_2 which is not defined in the above code.

Output:

jdoodle.scala:4: error: invalid literal number
        var 3value_2 = 65
            ^
jdoodle.scala:6: error: '=' expected.
        println("The sum of two values is " + (_value1 + value_2))
^

41. Which variable in Scala can save memory while declaring variables?

  1. Mutable variables
  2. Lazy Variables
  3. Inherited Variables
  4. None of these

Answer: B Lazy Variables

Explanation: Using the lazy keyword, you can halt the initialization of the variable until the time it is first used or accessed in the code.

42. How many types of operators are present in Scala?

  1. 5
  2. 2
  3. 6
  4. 8

Answer: A 5

Explanation: There are 5 types of operators in Scala, they are:

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators

43. Logical operators in Scala are used to –

  1. Perform a comparison of values
  2. Perform logical operation on the boolean value
  3. Return a value
  4. None

Answer: B Perform logical operation on the boolean value

Explanation: Logical operators, logical-or (|| and | ) and logical-and (&& and &) take Boolean operands and evaluate to a Boolean result.

44. What is the use of the “&=” operator in Scala –

  1. Bitwise operator
  2. Arithmetic operator
  3. Bitwise Assignment operator
  4. None of these

Answer: C Bitwise Assignment operator

Explanation: The bitwise AND assignment operator (&=) uses the binary representation of both operands, does a bitwise AND operation on them and assigns the result to the variable.

45. Find the result of the following code block –

(3 + 4 * 5) >>>  1
  1. 43
  2. 11
  3. 12
  4. 120

Answer: B 11

46. Relation operators are –

  1. Return a relative value
  2. Used to define the comparison between the two operators
  3. Create new values based on the relation
  4. None of these

Answer: B Used to define the comparison between the two operators

Explanation: Relation operators are used to check whether the two operands are equal or not and returns true if they are equal

47. What is the symbolic operator in Scala?

  1. Predefined sets that can handle a specific task
  2. Are reserved to a specific use
  3. Symbols that have a specific task that they perform when called in a Scala program
  4. All of these

Answer: D All of these

Explanation: The symbolic operators in Scala are symbols that have a specific task that they perform when called in a Scala program. Scala library defines a lot of symbols that can be used while programming in Scala.

48. The final keyword in Scala is used to –

  1. Define a variable whose value cannot be further changed
  2. Create a new variable
  3. Special inaccessible value in Scala
  4. None of these

Answer: A Define a variable whose value cannot be further changed

Explanation: In Scala, Final is a keyword and used to impose restriction on super class or parent class through various ways.

49. A final method can be applied on?

  1. Variables
  2. Classes
  3. Functions
  4. All of these

Answer: D All of these

Explanation: The final method can be used with variables, functions as well as classes.

50. What is the scope of a local variable in Scala?

  1. Whole program
  2. A method is it declared in
  3. Class/object containing it
  4. All of the above

Answer: B A method is it declared in

Explanation: Local variables of methods have scope restricted to that of methods in Scala.

51. 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. 43
  3. Error
  4. None of these

Answer: C Error

Explanation: totalMarks is a local variable of printTotal() method. Hence, cannot be used outside it.

52. Which is valid to method to increase value of variable by one?

  1. a++
  2. ++a
  3. a += 1
  4. All of these

Answer: C a += 1

Explanation: The Scala programming language doesn’t support unary operators (++ or –). In Scala, the binary operators are used to increment and decrement an integer.

53. 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. All of the above

Answer: B 44

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

Answer: A Create variables without using names

Explanation: When we don’t care about variables for constructed entries, we can ignore them using the underscore.

55. Wildcard patterns (_) is used to –

  1. Create variables
  2. Create new unmatched patterns
  3. Match the unmatched case
  4. None of these

Answer: C Match the unmatched case

Explanation: The wildcard pattern ( _ ) matches any object whatsoever.

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

Answer: C Import all methods from java.util library

Explanation: import java.util._ imports all methods from java.util library.

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

Answer: A Line of code that compiles to a value

Explanation: The expressions are the line of code that compiles to a value.

58. Conditional statement in Scala executes a block of code based on some conditional value?

  1. True
  2. False

Answer: A True

Explanation: The above given statement is true.

59. Which of these is not a conditional statement in Scala?

  1. if statement
  2. if-else statement
  3. This statement
  4. None of these

Answer: C This statement

Explanation: This statement is not a conditional statement in Scala.

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

Answer: C C

61. The do-while loop in Scala is –

  1. Iteration control Loop
  2. Entry control loop
  3. Exit control loop
  4. None of these

Answer: C Exit control loop

Explanation: The do-while loop is an exit control loop, where loop body executes before evaluating the test condition.

62. The for loop in Scala is –

  1. Iteration control loop
  2. Entry control loop
  3. Exit control loop
  4. None of these

Answer: A Iteration control loop

Explanation: The for loop is an iteration control loop.

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

Answer: A 12

64. 2-D structures in Scala can be looped using –

  1. Nested Loop
  2. Structure
  3. Collection iteration
  4. None of these

Answer: A Nested Loop

Explanation: The 2-D structure can be looped using the nested loop.

65. Output of the following block of code –

for(i <- 1 to 2){
for(j <- 1 to 2)
print(“(” + i + “,” + j + “)\t”)
}

  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

Answer: B (1,1) (1,2) (2,1) (2,2)

66. The break statement in Scala is imported using –

  1. import scala.util.control._
  2. import scala.break
  3. import control._
  4. None of these

Answer: C pi()

Explanation: The break statement in Scala is imported using import scala.util.control._.

67. 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 these

Answer: D All of these

Explanation: For each iteration of your for loop, yield generates a value which is remembered by the for loop.

68. Can there be multiple counters in a for loop in Scala?

  1. Yes
  2. No

Answer: A Yes

Explanation: Yes, there can be multiple counters in a for loop in Scala.

69. To create a loop breakable in Scala, do we need to enclose it?

  1. break
  2. loop.breakable
  3. breaks
  4. None of these

Answer: B loop.breakable

Explanation: To create a loop breakable in Scala, do we need to enclose it by loop.breakable.

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

Answer: A No parameter is passed

Explanation: The default arguments are used when you provide no arguments or only few arguments while calling a function.

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

Answer: C 26

72. Recursion function is –

  1. A function that calls itself multiple times
  2. Has a loop statement
  3. All of these
  4. None of these

Answer: A A function that calls itself multiple times

Explanation: Recursion is the process of defining a problem (or the solution to a problem) in terms of (a simpler version of) itself.

73. Which of these can be solved using recursion?

  1. Factorial
  2. Fibonacci
  3. Both A and B
  4. None of these

Answer: C Both A and B

Explanation: The both Factorial and Fibonacci series can be extracted using the recursion.

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

Answer: B Redefining methods in different ways under the same name

Explanation: Scala Method overloading is when one class has more than one method with the same name but different signature.

75. The output of the following block of code is –

object MyClass {
def datatype(x:Int){
println(“The parameter is of Integer datatype”)
}

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

Answer: D The parameter is of Float data type

76. Which statement in Scala is used to create a tail-recursive function –

  1. @newtailRec
  2. @tailRecFunc
  3. @tailRec
  4. @tailrec

Answer: D @tailrec

Explanation: The @tailrec is is used to create a tail-recursive function.

77. Tail recursion in Scala is –

  1. Initiated from last
  2. Initiated from the first call

Answer: A Initiated from last

Explanation: The tail recursion is initiated from the last.

78. What is the maximum number of parameters a method can accept?

  1. 32
  2. 64
  3. 128
  4. 255

Answer: D 255

Explanation: The number of method parameters is limited to 255 by the definition of a method descriptor.

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

Answer: C (args: String*)

Explanation: The syntax to pass the variable argument to function in Scala is:

(args: String*)

80. Can you alter the sequence of parameter passing?

  1. Yes
  2. No

Answer: A Yes

Explanation: Yes, you can alter the sequence of parameter passing.

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

Answer: B 2

Explanation: Named arguments are passed and used.

82. 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 these

Answer: C Functions that use a value from outside of the function’s body

Explanation: The Scala Closures are functions which uses one or more free variables and the return value of this function is dependent of these variable.

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

Answer: D 225

Explanation: The calculator method is a closure.

84. 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 these

Answer: C Parenthesis ()

Explanation: Read: Parameterless method in Scala

85. 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 these

Answer: D All of these

Explanation: All of the above-mentioned methods can be used to invoke a method in Scala.

86. Lambda expression stores the value of –

  1. Variable
  2. Constant
  3. Function
  4. None of these

Answer: C Function

Explanation: In Scala, the lambda expression stores the value of the function.

87. Can Lambda expressions be used on collections in Scala?

  1. Yes
  2. No

Answer: A Yes

Explanation: Yes, the lambda expressions can be used on the collections in Scala.

88. Ways to define a composite function in Scala are –

  1. Compose keyword
  2. andthen keyword
  3. Passing method to another method
  4. All of these

Answer: D All of these

Explanation: There are multiple ways to define the composition of a function. They are,

  1. Using compose Keyword
  2. Using andthen Keyword
  3. Passing method to method

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

Answer: C 90

Explanation: Here, functions are used in composition and the result is an integer value that causes the loss in data.

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

Answer: B Strip off new line characters

Explanation: The string chomp(or chop) function in Scala is used to chop off the end of line characters.

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

Answer: D All of these

Explanation: Read more: How to return the Unit from a Scala function?

92. 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 these

Answer: C Linear data structure with a fixed number of elements

Explanation: Array is a linear data structure with a fixed number of elements.

93. Which Scala keyword is used to create an array?

  1. Arr
  2. array
  3. Array
  4. All of these

Answer: C Array

Explanation: The Array keyword is used to create an array.

94. 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 these

Answer: D All of these

Explanation: Read more: How to print an array in Scala?

95. Is array mutable in Scala?

  1. Yes
  2. No

Answer: B No

Explanation: To create a mutable array in Scala arrayBuffer is used.

96. 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 these

Answer: B Using arrayBuffer

97. 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 these

Answer: A arrayBuffer.remove()

Explanation: The Scala method arrayBuffer.remove() is used to remove/delete from arrayBuffer.

98. Method used to get the length of array in Scala –

  1. Array.len
  2. length(arr)
  3. arr.size
  4. sizeof(arr)

Answer: C arr.size

Explanation: Scala method arr.size is used to get the length of an array.

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

Answer: C A collection that stores data in the form of a linked-list

Explanation: Read more: Scala Lists

100. Method used to check if a list is empty in Scala –

  1. list.isEmpty
  2. list.isNull
  3. list.empty
  4. None of these

Answer: A list.isEmpty

Explanation: Scala method list.isEmpty is used to check if a list is empty.

Scala objective questions with answers pdf download online exam test

Leave a Reply

Your email address will not be published. Required fields are marked *