Basic Scala Interview Questions and Answers

Question 1
What is functional programming ?

Functional programming is a style of programming where pure functions and immutable values are the basic building blocks.

Question 2
Is Scala a functional language ?

Scala is a multi-paradigm programming language, it supports imperative and functional style.

Question 3
What is the difference between ‘val’ and ‘var’.

If the variable is declared with the keyword “val” it means it’s immutable, cannot be reassigned to a new value.  Mutable variables are declared with the keyword “var“.

Question 4
What is Option ?

Option is a container which can contains one (represented by Some) or zero (represented by None) elements.

Question 5
What is Type Inference ?

Type Inference is ability of Scala compiler to deduct data type of an expression.

The compiler will infer missing type of variable myString.

Quesstion 6
What is a recursive function ?

A recursive function is a function that may invoke itself.

Quesstion 7
Provide an example of try/catch statement ?

Question 8
What is higher-order function ?

Function that takes other function as parameters or return function as return value.

Question 9
What is vararg parameter ?

The Scala varargs allows to pass a variable number of arguments to a method.

Question 10
Provide an example of pattern matching ?

Question 11
What is a trait ?

Trait is like a class, can contain methods and fields but it can not be instantiated.

Question 12
What is a singleton object ?

Singleton object is an object that is defined using object keyword, there can be only one instance of singleton object. As opposed to class it is not instantiated with new keyword but it is accessed by name.

Question 13
What is a Tuple ?

A tuple is an ordered collections of values. Unlike collections they can contains values of different types.

To access tuple elements we use accessors fields.

Leave a Reply

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