wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Scala - Syntax

Total questions: 25

Worksheet time: 14mins

Name
Class
Date
1.

Scala is a combination of which programming paradigms?

a)
Imperative and logic programming
b)
Object-oriented and functional programming
c)
Procedural and declarative programming
d)
Scripting and markup programming
2.

Scala programs are executed on which platform?

a)
Java Virtual Machine (JVM)
b)
Python Interpreter
c)
C# Framework
d)
Node.js Runtime
3.

Which keyword is used to declare a constant value in Scala?

a)
immutable
b)
val
c)
final
d)
const
4.

Which keyword is used to declare a mutable variable in Scala?

a)
let
b)
var
c)
const
d)
mutable
5.

What is the default return type of a Scala function if not specified?

a)
String
b)
Unit
c)
Void
d)
Boolean
6.

Which of the following is the entry point of a Scala application?

a)
def start(args: List[String]): Int
b)
def run(args: Array[Int]): String
c)
def main(args: Array[String]): Unit
d)
def execute(args: Seq[String]): Any
7.

Scala supports type inference. This means:

a)
Scala requires explicit type declarations for all variables.
b)
Scala only infers types for primitive data types.
c)
Scala cannot infer types in nested functions.
d)
Scala can determine the type of a variable or expression automatically.
8.

Which collection is immutable by default in Scala?

a)
List
b)

Array Buffer

c)

Hash map

d)
Array
9.

What does List(1,2,3).head return?

a)
2
b)
3
c)
1
d)
List(1,2,3)
10.

What does List(1,2,3).tail return?

a)
List(1,2,3,4)
b)
List(1,2)
c)
List(2,3)
d)
List(3)
11.

Which method is used to join collection elements into a string?

a)

join()

b)

concat()

c)

mkString()

d)

toString()

12.

What is the output of println(10 + "20")?

a)
210
b)

Error

c)

30

d)
1020
13.

Which data type represents no meaningful value in Scala?

a)
Unit
b)
Void
c)
Nothing
d)
Null
14.

What does contains() method return?

a)
An array of elements matching the input.
b)
A string representation of the input.
c)
A boolean value (true or false).
d)
An integer value (1 or 0).
15.

Which symbol is used for single-line comments in Scala?

a)

--

b)
# comment
c)
/* comment */
d)
//
16.

Which of the following is a valid Scala List?

a)

List[1,2,3]

b)

List(1,2,3)

c)

(1,2,3)

d)

{1,2,3}

17.

Which operator is used for string interpolation?

a)
%
b)
$
c)
@
d)
&
18.

What does Set(1,1,2,3) contain?

a)
{1, 2, 3}
b)
{2, 3, 4}
c)
{1, 2, 3, 4}
d)
{1, 2}
19.

Scala source files have which extension?

a)
.scala
b)
.java
c)
.kt
d)
.py
20.

Which method checks whether an element exists in a collection?

a)
contains or in
b)
exists or has
c)
check or verify
d)
find or search
21.

Which data type is the supertype of all Scala types?

a)
None
b)
Unit
c)
Nothing
d)
Any
22.

Scala code is compiled into which format?

a)
Java bytecode
b)
Java source code
c)
Python script
d)
C# code
23.

Which of the following is NOT a Scala keyword?

a)

def

b)

val

c)

function

d)

var

24.

Scala supports (a)   inference, where the compiler determines the data type automatically.

25.

In Scala, everything is treated as an (a)   .