Home »
MCQs
Scala Multiple-Choice Questions (MCQs)
Scala, the short form of Scalable language developed by Martin Odersky in 2003. Scala is a general-purpose programming language that supports both object-oriented as well as a functional programming paradigms.
Scala Programming MCQs: This section contains multiple-choice questions and answers on the Scala programming language. It will help the students to test their skills and prepare well for their exams.
List of Scala MCQs
1. Scala programming language was developed by -
- James Gosling
- Martin Odersky
- Dennis MacAlistair Ritchie
- Guido van Rossum
Answer: B) Martin Odersky
Explanation:
Scala is a programming language developed by Martin Odersky. It came into the market in 2003. [Read more: Overview of Scala]
Discuss this Question
2. What is the paradigm of the Scala programming language?
- Object-oriented
- Statically Types
- Functional
- 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.
Discuss this Question
3. Scala stands for ___.
- Scalable language
- Scripted advanced language
- Sequential language
- None
Answer: A) Scalable language
Explanation:
Scala stands for Scalable language.
Discuss this Question
4. Which of the following is not a feature of Scala?
- Type inference
- Lazy Computation
- High order function
- 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.
Discuss this Question
5. Is Java required before installing Scala on the system?
- Yes
- 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.
Discuss this Question
6. The semicolon (;) in Scala is -
- Necessary, failing to write will not mark the end of line
- Not required, it is treated as a character
- Optional, end of the line does not require ;
- 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
Discuss this Question
7. The Scala compiler starts executing from -
- The first line of code
- main() method
- main class
- 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.
Discuss this Question
8. Which of the following are not present in Scala?
- Closures
- Monads
- Traits
- None
Answer: D) None
Explanation:
All the above features are present in Scala.
Discuss this Question
9. The correct syntax for creating Single line comments in Scala is,
- //
- <!-- -- >
- /* */
- %%
Answer: A) //
Explanation:
// is used to create a single line comment in Scala. /*...*/ is used to create multiline comments in Scala.
Discuss this Question
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")
}
}
}
}
}
- 3 3
- 2 0
- 0 2
- 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.
Discuss this Question
11. Which of these is not a primary data type in Scala -
- Integer
- String
- Array
- Char
Answer: C) Array
Explanation:
Array is not a primary data in Scala.
Discuss this Question
12. The size of integer data type in Scala is -
- 256 bits
- 4 bits
- 32 bits
- 64 bits
Answer: C) 32 bits
Explanation:
An Integer is a 32-bit value and is central to any numeric representation in Scala.
Discuss this Question
13. Why is Double better than Float values?
- It can store double-precision values providing more accurate data to be stored.
- It stores 64 bits values instead of 32 bits from a float.
- Float Values are better
- 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.
Discuss this Question
14. Which class is the super-class of all classes in Scala?
- Ref
- AnyRef
- Any
- 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.
Discuss this Question
15. Which type class does not inherit AnyVar?
- Char
- Int
- Float
- Pointer
Answer: D) Pointer
Explanation:
All the other values inherit AnyVar class.
Discuss this Question
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)
}
}
- a = 454.32138988 b = 454.32138988152344
- a = 454.32138 b = 454.3213806152344
- a = 454.32138 b = 454.32138
- error
Answer: A) a = 454.32138988 b = 454.32138988152344
Discuss this Question
17. Default values of string type when it is not initialized -
- 0
- Null
- None
- " "
Answer: B) Null
Explanation:
The default value of the string variable is Null.
Discuss this Question
18. Which type in Scala is a subtype of all types -
- Int
- Ref
- Boolean
- Nothing
Answer: D) Nothing
Explanation:
In Scala, Nothing is treated as the subtype of all types.
Discuss this Question
19. Statement returned by function when no values are returned in Scala -
- No value
- Unit
- Int
- None of these
Answer: B) Unit
Explanation:
Statement returned by function when no values are returned in Scala is Unit.
Discuss this Question
20. In Scala, can you return two values?
- Yes
- No
Answer: A) Yes
Explanation:
In Scala, Options are used to return two instances.
Discuss this Question
21. What is the range defined by the below statement -
range(13, 17, 2)
- 13 14 15 16 17
- 13 14 15 16
- 13 15
- 13 15 17
Answer: C) 13 15
Explanation:
The range will exclude the last value and iterate by 2 for each value.
Discuss this Question
22. Which is not a Scala method for printing text on the screen?
- print()
- printf()
- printl()
- println()
Answer: C) printl()
Explanation:
The printl() is not a valid Scala method. All three above mentioned methods are used for printing.
Discuss this Question
23. What is the output of following code?
val i = 43
i = 231
printf(i)
- 231
- 43
- 0
- Error
Answer: D) Error
Explanation:
The val keyword defines immutable values in Scala. [Read more: Scala Literal, Variables and Data Type]
Discuss this Question
24. Literals in Scala are ___.
- Name of the variables
- A literal is a value that can be assigned to a variable
- The type of the values
- 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
Discuss this Question
25. Based on Type Casting, which of these conversions is lossy or invalid?
- Character -> Float
- Float -> Long
- Short -> Integer
- Integer -> Double
Answer: B) Float -> Long
Explanation:
Float - > Long is not a valid type casting. [Refer diagram given here: Scala Type Casting]
Discuss this Question
26. Which type of typecasting is done by the compiler?
- Implicit Conversion
- Explicit Conversion
- Instance conversion
- 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.
Discuss this Question
27. Explicit Conversion is -
- Done by the compiler itself
- Defined by the user
- Both A and B
- 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.
Discuss this Question
28. The getClass() method is used to -
- Extract the class of the given number
- Extract the value of the variable
- Extract the memory location of the variable
- 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.
Discuss this Question
29. Converting Character to Integer will return -
- Error
- Random integer value
- ASCII value of the character
- 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.
Discuss this Question
30. Which Scala keyword is used to initialize a variable?
- int
- var
- value
- None
Answer: B) var
Explanation:
Scala variables are created using the var keyword.
Discuss this Question
31. Lazy initialization is -
- Creating variables using the lazy keyword
- Done only on immutable variables
- Calculated at its first access
- 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.
Discuss this Question
32. The total number of keywords in Scala are -
- 45
- 34
- 39
- 52
Answer: C) 39
Explanation:
There are in total 39 keywords present in Scala. [Learn more: Scala Keywords]
Discuss this Question
33. Which of these is not a keyword in Scala?
- int
- var
- forsome
- package
Answer: A) int
Explanation:
"int" is not a Scala keyword.
Discuss this Question
34. Using a keyword as a value will lead to -
- Error
- Compile with the NULL value
- Warning
- None of these
Answer: A) Error
Explanation:
The compiler will throw an error if we try to use keywords as identifiers.
Discuss this Question
35. Is 'sealed' a keyword in Scala -
- Yes
- No
Answer: A) Yes
Explanation:
Yes, the sealed is a keyword in Scala.
Discuss this Question
36. Identifiers in Scala are names given to -
- Classes or objects
- Methods
- Objects
- 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.
Discuss this Question
37. Which of these is not a type of identifier -
- Alphanumeric identifier
- Operator identifier
- Literal identifier
- Value identifier
Answer: D) Value identifier
Explanation:
In Scala, we have 4 different types of identifiers defined. They are:
- Alphanumeric Identifiers
- Operator Identifiers
- Mixed Identifiers
- Literal Identifiers
Discuss this Question
38. Is the following identifier valid?
12Scala_3
- Yes
- No
Answer: B) No
Explanation:
"12Scala_3" is not a valid identifier. The identifiers must be started either an alphabet or an underscore (_).
Discuss this Question
39. Literal Identifier is -
- String literal used as an identifier in Scala
- Value literal used as an identifier in Scala
- Numeric literal used as an identifier in Scala
- None
Answer: A) String literal used as an identifier in Scala
Discuss this Question
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))
}
}
- 54
- Error
- 119
- 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))
^
Discuss this Question
41. Which variable in Scala can save memory while declaring variables?
- Mutable variables
- Lazy Variables
- Inherited Variables
- 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.
Discuss this Question
42. How many types of operators are present in Scala?
- 5
- 2
- 6
- 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
Discuss this Question
43. Logical operators in Scala are used to -
- Perform a comparison of values
- Perform logical operation on the boolean value
- Return a value
- 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.
Discuss this Question
44. What is the use of the "&=" operator in Scala -
- Bitwise operator
- Arithmetic operator
- Bitwise Assignment operator
- 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.
Discuss this Question
45. Find the result of the following code block -
(3 + 4 * 5) >>> 1
- 43
- 11
- 12
- 120
Answer: B) 11
Discuss this Question
46. Relation operators are -
- Return a relative value
- Used to define the comparison between the two operators
- Create new values based on the relation
- 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
Discuss this Question
47. What is the symbolic operator in Scala?
- Predefined sets that can handle a specific task
- Are reserved to a specific use
- Symbols that have a specific task that they perform when called in a Scala program
- 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.
Discuss this Question
48. The final keyword in Scala is used to -
- Define a variable whose value cannot be further changed
- Create a new variable
- Special inaccessible value in Scala
- 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.
Discuss this Question
49. A final method can be applied on?
- Variables
- Classes
- Functions
- All of these
Answer: D) All of these
Explanation:
The final method can be used with variables, functions as well as classes.
Discuss this Question
50. What is the scope of a local variable in Scala?
- Whole program
- A method is it declared in
- Class/object containing it
- 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.
Discuss this Question
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)
}
}
- 500
- 43
- Error
- None of these
Answer: C) Error
Explanation:
totalMarks is a local variable of printTotal() method. Hence, cannot be used outside it.
Discuss this Question
52. Which is valid to method to increase value of variable by one?
- a++
- ++a
- a += 1
- 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.
Discuss this Question
53. 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
- All of the above
Answer: B) 44
Discuss this Question
54. Ignored variables are used to -
- Create variables without using names
- Create blank value variable
- Both A and B
- 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.
Discuss this Question
55. Wildcard patterns (_) is used to -
- Create variables
- Create new unmatched patterns
- Match the unmatched case
- None of these
Answer: C) Match the unmatched case
Explanation:
The wildcard pattern ( _ ) matches any object whatsoever.
Discuss this Question
56. The following code statement will -
import java.util._
- import _ method from util library
- Error
- Import all methods from java.util library
- None of these
Answer: C) Import all methods from java.util library
Explanation:
import java.util._ imports all methods from java.util library.
Discuss this Question
57. 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
Answer: A) Line of code that compiles to a value
Explanation:
The expressions are the line of code that compiles to a value.
Discuss this Question
58. Conditional statement in Scala executes a block of code based on some conditional value?
- True
- False
Answer: A) True
Explanation:
The above given statement is true.
Discuss this Question
59. Which of these is not a conditional statement in Scala?
- if statement
- if-else statement
- This statement
- None of these
Answer: C) This statement
Explanation:
This statement is not a conditional statement in Scala.
Discuss this Question
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");
- A
- B
- C
- None of these
Answer: C) C
Discuss this Question
61. The do-while loop in Scala is -
- Iteration control Loop
- Entry control loop
- Exit control loop
- 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.
Discuss this Question
62. The for loop in Scala is -
- Iteration control loop
- Entry control loop
- Exit control loop
- None of these
Answer: A) Iteration control loop
Explanation:
The for loop is an iteration control loop.
Discuss this Question
63. 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
Answer: A) 12
Discuss this Question
64. 2-D structures in Scala can be looped using -
- Nested Loop
- Structure
- Collection iteration
- None of these
Answer: A) Nested Loop
Explanation:
The 2-D structure can be looped using the nested loop.
Discuss this Question
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,1) (1,2) (2,1) (2,2)
- (1,1) (2,2) (1,1) (2,2)
- None of these
Answer: B) (1,1) (1,2) (2,1) (2,2)
Discuss this Question
66. The break statement in Scala is imported using -
- import scala.util.control._
- import scala.break
- import control._
- None of these
Answer: C) pi()
Explanation:
The break statement in Scala is imported using import scala.util.control._.
Discuss this Question
67. 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 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.
Discuss this Question
68. Can there be multiple counters in a for loop in Scala?
- Yes
- No
Answer: A) Yes
Explanation:
Yes, there can be multiple counters in a for loop in Scala.
Discuss this Question
69. To create a loop breakable in Scala, do we need to enclose it?
- break
- loop.breakable
- breaks
- None of these
Answer: B) loop.breakable
Explanation:
To create a loop breakable in Scala, do we need to enclose it by loop.breakable.
Discuss this Question
70. The default parameters are used when -
- No parameter is passed
- The extra parameter is passed
- Always when the function is called
- 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.
Discuss this Question
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);
}
}
- 75
- 59
- 26
- 10
Answer: C) 26
Discuss this Question
72. Recursion function is -
- A function that calls itself multiple times
- Has a loop statement
- All of these
- 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.
Discuss this Question
73. Which of these can be solved using recursion?
- Factorial
- Fibonacci
- Both A and B
- None of these
Answer: C) Both A and B
Explanation:
The both Factorial and Fibonacci series can be extracted using the recursion.
Discuss this Question
74. 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
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.
Discuss this Question
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)
}
}
- 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
Answer: D) The parameter is of Float data type
Discuss this Question
76. Which statement in Scala is used to create a tail-recursive function -
- @newtailRec
- @tailRecFunc
- @tailRec
- @tailrec
Answer: D) @tailrec
Explanation:
The @tailrec is is used to create a tail-recursive function.
Discuss this Question
77. Tail recursion in Scala is -
- Initiated from last
- Initiated from the first call
Answer: A) Initiated from last
Explanation:
The tail recursion is initiated from the last.
Discuss this Question
78. What is the maximum number of parameters a method can accept?
- 32
- 64
- 128
- 255
Answer: D) 255
Explanation:
The number of method parameters is limited to 255 by the definition of a method descriptor.
Discuss this Question
79. 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
Answer: C) (args: String*)
Explanation:
The syntax to pass the variable argument to function in Scala is:
(args: String*)
Discuss this Question
80. Can you alter the sequence of parameter passing?
- Yes
- No
Answer: A) Yes
Explanation:
Yes, you can alter the sequence of parameter passing.
Discuss this Question
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);
}
}
- -2
- 2
- Error
- None of these
Answer: B) 2
Explanation:
Named arguments are passed and used.
Discuss this Question
82. 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's body
- 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.
Discuss this Question
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;
}
- 45
- 5
- Error
- 225
Answer: D) 225
Explanation:
The calculator method is a closure.
Discuss this Question
84. Which of these parts of the declaration are not required in the case of parameter less methods?
- def keyword
- Return type
- Parenthesis ()
- All of these
Answer: C) Parenthesis ()
Explanation:
Read: Parameterless method in Scala
Discuss this Question
85. 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 these
Answer: D) All of these
Explanation:
All of the above-mentioned methods can be used to invoke a method in Scala.
Discuss this Question
86. Lambda expression stores the value of -
- Variable
- Constant
- Function
- None of these
Answer: C) Function
Explanation:
In Scala, the lambda expression stores the value of the function.
Discuss this Question
87. Can Lambda expressions be used on collections in Scala?
- Yes
- No
Answer: A) Yes
Explanation:
Yes, the lambda expressions can be used on the collections in Scala.
Discuss this Question
88. Ways to define a composite function in Scala are -
- Compose keyword
- andthen keyword
- Passing method to another method
- All of these
Answer: D) All of these
Explanation:
There are multiple ways to define the composition of a function. They are,
- Using compose Keyword
- Using andthen Keyword
- Passing method to method
Discuss this Question
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
}
}
- 45200
- 0
- 90
- Error
Answer: C) 90
Explanation:
Here, functions are used in composition and the result is an integer value that causes the loss in data.
Discuss this Question
90. 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
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.
Discuss this Question
91. 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
Answer: D) All of these
Explanation:
Read more: How to return the Unit from a Scala function?
Discuss this Question
92. 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 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.
Discuss this Question
93. Which Scala keyword is used to create an array?
- Arr
- array
- Array
- All of these
Answer: C) Array
Explanation:
The Array keyword is used to create an array.
Discuss this Question
94. 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 these
Answer: D) All of these
Explanation:
Read more: How to print an array in Scala?
Discuss this Question
95. Is array mutable in Scala?
- Yes
- No
Answer: B) No
Explanation:
To create a mutable array in Scala arrayBuffer is used.
Discuss this Question
96. How to create a mutable array in Scala?
- Initializing using the var keyword
- Using arrayBuffer
- Adding mutable before initialization
- All of these
Answer: B) Using arrayBuffer
Explanation:
Read more: ArrayBuffer in Scala (Creating Mutable Arrays)
Discuss this Question
97. Methods which can be used to remove/ delete users from arrayBuffer in Scala?
- arrayBuffer.remove()
- arrayBuffer.delete()
- arrayBuffer.push()
- All of these
Answer: A) arrayBuffer.remove()
Explanation:
The Scala method arrayBuffer.remove() is used to remove/delete from arrayBuffer.
Discuss this Question
98. Method used to get the length of array in Scala -
- Array.len
- length(arr)
- arr.size
- sizeof(arr)
Answer: C) arr.size
Explanation:
Scala method arr.size is used to get the length of an array.
Discuss this Question
99. 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
Answer: C) A collection that stores data in the form of a linked-list
Explanation:
Read more: Scala Lists
Discuss this Question
100. Method used to check if a list is empty in Scala -
- list.isEmpty
- list.isNull
- list.empty
- None of these
Answer: a) list.isEmpty
Explanation:
Scala method list.isEmpty is used to check if a list is empty.
Discuss this Question