Top 15 Scala Interview Questions And Answers

 

1) What does Scala stands for?

Scala stands for Scalable language.


2) What is Scala?

Scala is a high-level, multi-paradigm programming language. It is a pure object-oriented programming language which also provides support to the functional programming approach. Scala programs can convert to bytecodes and run on the JVM (Java Virtual Machine).


3) What are the key features of Scala?

Following are the key features of Scala:

● Scala is object-oriented programming language
● Scala is functional language
● Scala is statically typed
● Scala runs on the JVM
● Scala can execute Java code
● Scala can do Concurrent & Synchronize processing


4) Why Scala is statically typed?

Scala does not expect to provide redundant type information i.e. there is no need to specify a type in most of the cases.


5) What are the Scala Web Frameworks?

Scala is being used everywhere and importantly in enterprise web applications. Some of the popular Scala Web Frameworks are:

● The Lift Framework
● The Play framework
● The Bowler framework


6) What is Closure in scala program?

A closure is a function, whose return value depends on the value of one or more variables declared outside this function.


7) What are Traits in scala program?

A trait encapsulates method and field definitions, which can then be reused by mixing them into classes. Traits are used to define object types by specifying the signature of the supported methods.


8) What are the different modes in which we can run Scala program?

Scala program can be executed in two different modes:

● Interactive mode
● Script mode


9) How to run Scala program?

The'scalac' command is used to compile the Scala program and it will generate a class file which then can be run on Java Virtual Machine (JVM) using 'scala' command. Below is the sample:

\> scalac HelloWorld.scala
\> scala HelloWorld


10) Is '$age' a legal identifier in Scala?

The '$' character is a reserved keyword in Scala and should not be used in identifiers. So $age is illegal identifier in Scala.


11) What is Unit data type in Scala?

In Scala Unit data type corresponds to no value.


12) What are mutable variables in Scala?

In Scala mutable variables are the variables that can change value. These mutable variables should be declared using the keyword var. Below is the syntax:

\>var myVar : String = "abc"


13) What are immutable variables in Scala?

In Scala immutable variables are the variables that cannot change value. These immutable variables should be declared using the keyword val. Below is the syntax:

\>val myVar : String = "abc"


14) What are the different scopes of variables in Scala?

Following are the different scopes of variables in Scala:

● Fields
● Method Parameters
● Local Variables


15) What are fields in scala?

In Scala fields are variables that belong to an object. The fields are accessible from inside every method in the object. It can also be accessible outside the object depending on what access modifiers are used to declare fields.


 

Related links: