Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

51.

How To Define Factory Methods Using Object Keyword In Scala? What Is The Use Of Defining Factory Methods In Object?

Answer»

In Scala, we USE ‘object’ keyword to define Factory methods. The main purpose of these Factory methods in Scala is to avoid using ‘new’ keyword. Without using ‘new’ keyword we can create OBJECTS.

To define Factory methods:

We can use apply method to define Factory methods in Scala. If we have Primary Constructor and Multiple Auxiliary CONSTRUCTORS, then we NEED to define multiple apply methods as shown below.

class Person(val FIRSTNAME: String, val middleName: String, val lastName: String){
def this(firstName: String, lastName: String){
this(firstName,"",lastName)
}
}
object Person{
def apply(val firstName: String, val middleName: String, val lastName: String) 
= new Person(firstName,middleName,lastName)
 
def apply(val firstName: String, val lastName: String) 
= new Person(firstName, lastName)
}
Now we can create Person objects without using new keyword or with new keyword upto your wish.
val p1 = new Person("Scala","Java")
or 
val p1 = Person("Scala","Java")

In Scala, we use ‘object’ keyword to define Factory methods. The main purpose of these Factory methods in Scala is to avoid using ‘new’ keyword. Without using ‘new’ keyword we can create objects.

To define Factory methods:

We can use apply method to define Factory methods in Scala. If we have Primary Constructor and Multiple Auxiliary constructors, then we need to define multiple apply methods as shown below.

class Person(val firstName: String, val middleName: String, val lastName: String){
def this(firstName: String, lastName: String){
this(firstName,"",lastName)
}
}
object Person{
def apply(val firstName: String, val middleName: String, val lastName: String) 
= new Person(firstName,middleName,lastName)
 
def apply(val firstName: String, val lastName: String) 
= new Person(firstName, lastName)
}
Now we can create Person objects without using new keyword or with new keyword upto your wish.
val p1 = new Person("Scala","Java")
or 
val p1 = Person("Scala","Java")

52.

What Is The Use Of “object” Keyword In Scala? How To Create Singleton Objects In Scala?

Answer»

In Scala, object keyword is used the following purposes:

  • It is used to create singleton object in Scala.
  • object MySingletonObject
  • Here, MySingletonObject becomes singleton object automatically.

object keyword is used to DEFINE Scala Applications that is executable Scala programs.

object MyScalaExecutableProgram{
def main(args: Array[String]){
println("Hello World")
}
}

When we define main method in object as shown above (its same as main() method in Java), it becomes automatically as a executable Scala program.

It is used to define static MEMBERS LIKE static variables and static methods without using ‘static’ keyword.

object MyScalaStaticMembers{ 
VAL PI: Double = 3.1414 
def add(a: Int, b: Int) = a + b
}

By def PI VARIABLE and add methods will become as static members. That means we can call them without creating a separate object like MyScalaStaticMembers.add(10,20).

In Scala, object keyword is used the following purposes:

object keyword is used to define Scala Applications that is executable Scala programs.

object MyScalaExecutableProgram{
def main(args: Array[String]){
println("Hello World")
}
}

When we define main method in object as shown above (its same as main() method in Java), it becomes automatically as a executable Scala program.

It is used to define static members like static variables and static methods without using ‘static’ keyword.

object MyScalaStaticMembers{ 
val PI: Double = 3.1414 
def add(a: Int, b: Int) = a + b
}

By def PI variable and add methods will become as static members. That means we can call them without creating a separate object like MyScalaStaticMembers.add(10,20).

53.

Why Scala Does Not Have “static” Keyword? What Is The Main Reason For This Decision?

Answer»

As we know, Scala does NOT have “static” KEYWORD at all. This is the design DECISION done by Scala Team.

The main reason to take this decision is to make Scala as a Pure OBJECT-Oriented Language. “static” keyword MEANS that we can access that class members without creating an object or without using an object. This is completely against with OOP principles.

If a Language supports “static” keyword, then that Language is not a Pure Object-Oriented Language. For instance, as Java supports “static” keyword, it is NOT a Pure Object-Oriented Language. But Scala is a Pure Object-Oriented Language.

As we know, Scala does NOT have “static” keyword at all. This is the design decision done by Scala Team.

The main reason to take this decision is to make Scala as a Pure Object-Oriented Language. “static” keyword means that we can access that class members without creating an object or without using an object. This is completely against with OOP principles.

If a Language supports “static” keyword, then that Language is not a Pure Object-Oriented Language. For instance, as Java supports “static” keyword, it is NOT a Pure Object-Oriented Language. But Scala is a Pure Object-Oriented Language.

54.

What Is Diamond Problem? How Scala Solves Diamond Problem?

Answer»

A Diamond Problem is a Multiple Inheritance problem. Some people calls this problem as Deadly Diamond Problem.

In Scala, it OCCURS when a Class extends more than one Traits which have same method definition.

Unlike Java 8, Scala solves this diamond problem automatically by following some rules defined in Language. Those rules are called “Class LINEARIZATION”.

Example:-

trait A{
def display(){ println("From A.display") }
}
trait B extends A{ 
override def display() { println("From B.display") }
}
trait C extends A{ 
override def display() { println("From C.display") }
}
class D extends B with C{ }
 
object ScalaDiamonProblemTest extends App {
VAL d = new D
d display
}

Here OUTPUT is “From C.display” form trait C. Scala Compiler reads “extends B with C” from right to left and takes “display” method definition from lest most trait that is C.

A Diamond Problem is a Multiple Inheritance problem. Some people calls this problem as Deadly Diamond Problem.

In Scala, it occurs when a Class extends more than one Traits which have same method definition.

Unlike Java 8, Scala solves this diamond problem automatically by following some rules defined in Language. Those rules are called “Class Linearization”.

Example:-

trait A{
def display(){ println("From A.display") }
}
trait B extends A{ 
override def display() { println("From B.display") }
}
trait C extends A{ 
override def display() { println("From C.display") }
}
class D extends B with C{ }
 
object ScalaDiamonProblemTest extends App {
val d = new D
d display
}

Here output is “From C.display” form trait C. Scala Compiler reads “extends B with C” from right to left and takes “display” method definition from lest most trait that is C.

55.

Difference Between Scala’s Inner Class And Java’s Inner Class?

Answer»

In JAVA, INNER class is associated with Outer class that is Inner class a member of the Outer class.

Unlike Java, SCALA treats the RELATIONSHIP between Outer class and Inner class differently. Scala’s Inner class is associated with Outer class object.

In Java, Inner class is associated with Outer class that is Inner class a member of the Outer class.

Unlike Java, Scala treats the relationship between Outer class and Inner class differently. Scala’s Inner class is associated with Outer class object.

56.

What Is The Relationship Between Equals Method And == In Scala? Differentiate Scala’s == And Java’s == Operator?

Answer»

compare two instances with ==, Scala calls that object’s EQUALS() METHOD automatically.

Java’s == operator is USED to check References EQUALITY that is whether two references are pointing to the same object or not. Scala’s == is used to check Instances Equality that is whether two instances are equal or not.

compare two instances with ==, Scala calls that object’s equals() method automatically.

Java’s == operator is used to check References Equality that is whether two references are pointing to the same object or not. Scala’s == is used to check Instances Equality that is whether two instances are equal or not.

57.

What Is The Difference Between “val” And “lazy Val” In Scala? What Is Eager Evaluation? What Is Lazy Evaluation?

Answer»

As we discussed in my Basic Scala Interview Questions, “val” means value or CONSTANT which is used to DEFINE IMMUTABLE variables.

There are two kinds of program EVALUATIONS:

Eager Evaluation means evaluating program at compile-time or program deployment-time irrespective of clients are using that program or not.

Lazy Evaluation means evaluating program at run-time on-demand that means when clients access the program then only its evaluated.

The difference between “val” and “lazy val” is that “val” is used to define variables which are evaluated eagerly and “lazy val” is also used to define variables but they are evaluated lazily.

As we discussed in my Basic Scala Interview Questions, “val” means value or constant which is used to define Immutable variables.

There are two kinds of program evaluations:

Eager Evaluation means evaluating program at compile-time or program deployment-time irrespective of clients are using that program or not.

Lazy Evaluation means evaluating program at run-time on-demand that means when clients access the program then only its evaluated.

The difference between “val” and “lazy val” is that “val” is used to define variables which are evaluated eagerly and “lazy val” is also used to define variables but they are evaluated lazily.

58.

Difference Between Array And List In Scala?

Answer»
  • ARRAYS are always MUTABLE where as LIST is always Immutable.
  • Once created, We can change ARRAY values where as we cannot change List Object.
  • Arrays are fixed-size data structures where as List is variable-sized data structures. List’s size is automatically increased or decreased BASED on it’s operations we perform on it.
  • Arrays are Invariants where as Lists are Covariants.

59.

How Do You Prove That By Default, Case Object Is Serializable And Normal Object Is Not?

Answer»

Yes, By DEFAULT, CASE Object is Serializable. But normal object is not. We can prove this by using isInstanaceOf method as SHOWN below:

SCALA> object MyNormalObject
defined object MyNormalObject

scala> MyNormalObject.isInstanceOf[Serializable]
res0: Boolean = false

scala> case object MyCaseObject
defined object MyCaseObject

scala> MyCaseObject.isInstanceOf[Serializable]
res1: Boolean = TRUE

Yes, By Default, Case Object is Serializable. But normal object is not. We can prove this by using isInstanaceOf method as shown below:

scala> object MyNormalObject
defined object MyNormalObject

scala> MyNormalObject.isInstanceOf[Serializable]
res0: Boolean = false

scala> case object MyCaseObject
defined object MyCaseObject

scala> MyCaseObject.isInstanceOf[Serializable]
res1: Boolean = true

60.

What Is The Usage Of Isinstanceof And Asinstanceof Methods In Scala? Is There Anything Similar Concept Available In Java?

Answer»

Both isInstanceOf and asInstanceOf methods are defined in Any CLASS. So no need import to get these methods into any class or OBJECT.

“isInstanceOf” method is used to test whether the object is of a given type or not. If so, it returns true. Otherwise returns false.

scala> val str = "HELLO"

scala>str.isInstanceOf[String]
res0: Boolean = false

“asInstanceOf” method is used to cast the object to the given a type. If the given object and type are of same type, then it cast to given type. Otherwise, it throws java.lang.ClassCastException.

scala> val str = "Hello".asInstanceOf[String]
str: String = Hello

In Java, ‘instanceof’ keyword is similar to Scala’s ‘isInstanceOf’ method. In Java, the following KIND of manual type casting is similar to Scala’s ‘asInstanceOf’ method.

AccountService service = (AccountService)
 context.getBean("accountService");

Both isInstanceOf and asInstanceOf methods are defined in Any class. So no need import to get these methods into any class or object.

“isInstanceOf” method is used to test whether the object is of a given type or not. If so, it returns true. Otherwise returns false.

scala> val str = "Hello"

scala>str.isInstanceOf[String]
res0: Boolean = false

“asInstanceOf” method is used to cast the object to the given a type. If the given object and type are of same type, then it cast to given type. Otherwise, it throws java.lang.ClassCastException.

scala> val str = "Hello".asInstanceOf[String]
str: String = Hello

In Java, ‘instanceof’ keyword is similar to Scala’s ‘isInstanceOf’ method. In Java, the following kind of manual type casting is similar to Scala’s ‘asInstanceOf’ method.

AccountService service = (AccountService)
 context.getBean("accountService");

61.

When Compare To Normal Class, What Are The Major Advantages Or Benefits Of A Case-class?

Answer»

The following are the major advantages or benefits of a Case CLASS over Normal Classes:

  • Avoids lots of boiler-plate code by adding some useful METHODS automatically.
  • By default, supports IMMUTABILITY because it’s parameters are ‘val’
  • Easy to USE in Pattern Matching.
  • No need to use ‘new’ keyword to CREATE instance of Case Class.
  • By default, supports Serialization and Deserialization.

The following are the major advantages or benefits of a Case class over Normal Classes:

62.

What Is Case Class? What Is Case Object? What Are The Advantages Of Case Class?

Answer»

Case class is a class which is defined with “case class” keywords. Case object is an object which is defined with “case object” keywords. Because of this “case” keyword, we will get some benefits to avoid boilerplate code.

We can create case class OBJECTS without USING “new” keyword. By DEFAULT, Scala compiler prefixes “val” for all constructor parameters. That’s why without using val or var, Case class’s constructor parameters will become class members, it is not possible for NORMAL classes.

Advantages of case class:

  • By default, Scala Compiler adds toString, hashCode and equals methods. We can avoid writing this boilerplate code.
  • By default, Scala Compiler adds companion object with apply and unapply methods that’s why we don’t need new keyword to create instances of a case class.
  • By default, Scala Compiler adds copy method too.
  • We can use case classes in Pattern Matching.
  • By default, Case class and Case Objects are SERIALIZABLE.

Case class is a class which is defined with “case class” keywords. Case object is an object which is defined with “case object” keywords. Because of this “case” keyword, we will get some benefits to avoid boilerplate code.

We can create case class objects without using “new” keyword. By default, Scala compiler prefixes “val” for all constructor parameters. That’s why without using val or var, Case class’s constructor parameters will become class members, it is not possible for normal classes.

Advantages of case class:

63.

What Are The Differences Between Array And Arraybuffer In Scala?

Answer»

Differences between ARRAY and ArrayBuffer in SCALA:

  • Array is fixed size array. We cannot change its size once its created.
  • ArrayBuffer is variable size array. It can INCREASE or decrease it’s size dynamically.
  • Array is something similar to Java’s PRIMITIVE ARRAYS.
  • ArrayBuffer is something similar to Java’s ArrayList.

Differences between Array and ArrayBuffer in Scala:

64.

What Is The Use Of Auxiliary Constructors In Scala?please Explain The Rules To Follow In Defining Auxiliary Constructors In Scala?

Answer»

In Scala, The main purpose of Auxiliary Constructors is to overload constructors. LIKE Java, We can provide various kinds of constructors so that USE can choose the right one BASED on his requirement.

Auxiliary Constructor Rules:

  • They are like methods only. Like methods, we should use ‘def’ keyword to define them.
  • We should use same NAME ‘this’ for all Auxiliary Constructors.
  • Each Auxiliary Constructor should start with a call to previous defined another Auxiliary Constructor or Primary Constructor. Otherwise compile-time error.
  • Each Auxiliary Constructor should differ with their parameters list: may be by number or types.
  • Auxiliary Constructors cannot call a super class constructors. They should call them through Primary Constructor only.
  • All Auxiliary Constructors call their Primary Constructor either directly or indirectly through other Auxiliary Constructors.

NOTE:- If you want to learn about Scala’s Constructors, please refer my Scala posts at: Primary Constructor and Auxiliary Constructor.

In Scala, The main purpose of Auxiliary Constructors is to overload constructors. Like Java, We can provide various kinds of constructors so that use can choose the right one based on his requirement.

Auxiliary Constructor Rules:

NOTE:- If you want to learn about Scala’s Constructors, please refer my Scala posts at: Primary Constructor and Auxiliary Constructor.

65.

What Is Primary Constructor? What Is Secondary Or Auxiliary Constructor In Scala? What Is The Purpose Of Auxiliary Constructor In Scala? Is It Possible To Overload Constructors In Scala?

Answer»

Scala has two kinds of constructors:

  • Primary Constructor
  • Auxiliary Constructor

Primary Constructor: In Scala, Primary Constructor is a constructor which is defined with class definition itself. Each class must have one Primary Constructor: Either PARAMETER constructor or Parameterless constructor.

Example:-

class Person

Above Person class has one Zero-parameter or No-Parameter or Parameterless Primary constructor to create instances of this class.

class Person (firstName: STRING, lastName: String)

Above Person class has a two PARAMETERS Primary constructor to create instances of this class.

Auxiliary Constructor: Auxiliary Constructor is also known as Secondary Constructor. We can declare a Secondary Constructor USING ‘def’ and ‘this’ keywords as shown below:

class Person (firstName: String, middleName:String, lastName: String){
def this(firstName: String, lastName: String){
this(firstName, "", lastName)
}
}

Scala has two kinds of constructors:

Primary Constructor: In Scala, Primary Constructor is a constructor which is defined with class definition itself. Each class must have one Primary Constructor: Either Parameter constructor or Parameterless constructor.

Example:-

class Person

Above Person class has one Zero-parameter or No-Parameter or Parameterless Primary constructor to create instances of this class.

class Person (firstName: String, lastName: String)

Above Person class has a two Parameters Primary constructor to create instances of this class.

Auxiliary Constructor: Auxiliary Constructor is also known as Secondary Constructor. We can declare a Secondary Constructor using ‘def’ and ‘this’ keywords as shown below:

class Person (firstName: String, middleName:String, lastName: String){
def this(firstName: String, lastName: String){
this(firstName, "", lastName)
}
}

66.

What Are The Different Types Of Scala Literals?

Answer»

The DIFFERENT TYPES of literals in scala are

  • Integer literals
  • Floating point literals
  • Boolean literals
  • SYMBOL literals
  • Character literals
  • STRING literals
  • Multi-Line strings

The different types of literals in scala are

67.

What Are The Four Types Of Scala Identifiers ?

Answer»

The FOUR TYPES of identifiers are

  • Alpha NUMERIC identifiers
  • OPERATOR identifiers
  • Mixed identifiers
  • Literal identifiers

The four types of identifiers are

68.

Why Scala Prefers Immutability?

Answer»

Scala prefers immutability in design and in MANY cases USES it as DEFAULT. Immutability can help when dealing with equality ISSUES or CONCURRENT programs.

Scala prefers immutability in design and in many cases uses it as default. Immutability can help when dealing with equality issues or concurrent programs.

69.

How Can You Format A String?

Answer»

To format a STRING, use the .format () METHOD, in SCALA you can use

VAL formatted= “%s %i”.format (mystring.myInt)

To format a string, use the .format () method, in scala you can use

Val formatted= “%s %i”.format (mystring.myInt)

70.

How Do I Append To The List?

Answer»

In scala to append into a LIST, use “:+” single value

VAR myList = List.empty[STRING]
myList :+= "a"
myList :+= "B"
myList :+= "C"
use++ for appending a list
var myList = List.empty[String]
myList ++= List("a", "b", "c")

In scala to append into a list, use “:+” single value

var myList = List.empty[String]
myList :+= "a"
myList :+= "b"
myList :+= "c"
use++ for appending a list
var myList = List.empty[String]
myList ++= List("a", "b", "c")

71.

What Are Option, Some And None In Scala?

Answer»

‘Option’ is a Scala GENERIC type that can EITHER be ‘some’ generic value or none. ‘Queue’ often uses it to represent PRIMITIVES that may be null.

‘Option’ is a Scala generic type that can either be ‘some’ generic value or none. ‘Queue’ often uses it to represent primitives that may be null.

72.

What Is The Difference Between Var And Value?

Answer»

In scala, you can define a variable using EITHER a, VAL or var keywords. The difference between val and var is, var is much LIKE JAVA DECLARATION, but val is little different. We cannot change the reference to point to another reference, once the variable is declared using val. The variable defined using var keywords are mutable and can be changed any number of times.

In scala, you can define a variable using either a, val or var keywords. The difference between val and var is, var is much like java declaration, but val is little different. We cannot change the reference to point to another reference, once the variable is declared using val. The variable defined using var keywords are mutable and can be changed any number of times.

73.

Explain ‘scala Higher Order’ Functions?

Answer»

Scala allows the definition of higher order functions. These are functions that take other functions as parameters, or whose result is a FUNCTION. In the following example, apply () function takes another function ‘f’ and a value ‘v’ and applies function to v.

Example:

object Test {
 DEF main(args: Array[String]) {
 PRINTLN( apply( LAYOUT, 10) )
 }
 def apply(f: Int => String, v: Int) = f(v)
 def layout[A](x: A) = "[" + x.toString() + "]"

When the above code is compiled and EXECUTED, it produces following result.

C:/>scalac Test.scala
C:/>scala Test
[10]
C:/>

Scala allows the definition of higher order functions. These are functions that take other functions as parameters, or whose result is a function. In the following example, apply () function takes another function ‘f’ and a value ‘v’ and applies function to v.

Example:

object Test {
 def main(args: Array[String]) {
 println( apply( layout, 10) )
 }
 def apply(f: Int => String, v: Int) = f(v)
 def layout[A](x: A) = "[" + x.toString() + "]"

When the above code is compiled and executed, it produces following result.

C:/>scalac Test.scala
C:/>scala Test
[10]
C:/>

74.

What Is Scala Anonymous Function?

Answer»

In a source code, ANONYMOUS functions are called ‘function literals’ and at run TIME, function literals are instantiated into objects called function VALUES. Scala provides a RELATIVELY EASY syntax for defining anonymous functions.

In a source code, anonymous functions are called ‘function literals’ and at run time, function literals are instantiated into objects called function values. Scala provides a relatively easy syntax for defining anonymous functions.

75.

What Is Monad In Scala?

Answer»

A MONAD is an object that WRAPS another object. You pass the Monad mini-programs, i.e functions, to perform the data MANIPULATION of the underlying object, INSTEAD of manipulating the object DIRECTLY. Monad chooses how to apply the program to the underlying object.

A monad is an object that wraps another object. You pass the Monad mini-programs, i.e functions, to perform the data manipulation of the underlying object, instead of manipulating the object directly. Monad chooses how to apply the program to the underlying object.

76.

What Is A Closure In Scala?

Answer»

A closure is a FUNCTION whose RETURN VALUE depends on the value of the variables declared OUTSIDE the function.

A closure is a function whose return value depends on the value of the variables declared outside the function.

77.

What Are Implicit Parameters In Scala?

Answer»

Implicit parameter is the way that allows parameters of a method to be “found”. It is similar to default parameters, but it has a DIFFERENT mechanism for finding the “default” value. The implicit parameter is a parameter to method or constructor that is marked as implicit. This means if a parameter value is not MENTIONED then the COMPILER will search for an “implicit” value defined within a SCOPE.

Implicit parameter is the way that allows parameters of a method to be “found”. It is similar to default parameters, but it has a different mechanism for finding the “default” value. The implicit parameter is a parameter to method or constructor that is marked as implicit. This means if a parameter value is not mentioned then the compiler will search for an “implicit” value defined within a scope.

78.

What Is Function Currying In Scala?

Answer»

Currying is the technique of TRANSFORMING a function that takes multiple arguments into a function that takes a single argument Many of the same techniques as LANGUAGE LIKE Haskell and LISP are SUPPORTED by Scala. Function currying is one of the LEAST used and misunderstood one.

Currying is the technique of transforming a function that takes multiple arguments into a function that takes a single argument Many of the same techniques as language like Haskell and LISP are supported by Scala. Function currying is one of the least used and misunderstood one.

79.

What Is The Use Of Tuples In Scala?

Answer»

SCALA TUPLES combine a FIXED number of items TOGETHER so that they can be passed around as whole. A tuple is immutable and can hold objects with different types, unlike an ARRAY or list.

Scala tuples combine a fixed number of items together so that they can be passed around as whole. A tuple is immutable and can hold objects with different types, unlike an array or list.

80.

What Is Case Classes?

Answer»

CASE classes provides a recursive decomposition mechanism via pattern matching, it is a regular classes which export their constructor parameter. The constructor PARAMETERS of case classes can be accessed DIRECTLY and are treated as public values.

Case classes provides a recursive decomposition mechanism via pattern matching, it is a regular classes which export their constructor parameter. The constructor parameters of case classes can be accessed directly and are treated as public values.

81.

When Can You Use Traits?

Answer»

There is no SPECIFIC rule when you can use traits, but there is a guideline which you can consider.

  • If the behaviour will not be reused, then make it a concrete class. Anyhow it is not a reusable behaviour.
  • In order to inherit from it in Java code, an abstract class can be USED.
  • If efficiency is a priority then LEAN TOWARDS using a class
  • Make it a trait if it might be reused in MULTIPLE and unrelated classes. In different parts of the class hierarchy only traits can be mixed into different parts.
  • You can use abstract class, if you want to distribute it in compiled form and expects outside groups to write classes inheriting from it.

There is no specific rule when you can use traits, but there is a guideline which you can consider.

82.

What Is ‘scala Trait’ In Scala?

Answer»

‘Traits’ are USED to define OBJECT types specified by the signature of the SUPPORTED methods. Scala allows to be partially implemented but traits may not have constructor parameters. A trait consists of method and field definition, by MIXING them into classes it can be REUSED.

‘Traits’ are used to define object types specified by the signature of the supported methods. Scala allows to be partially implemented but traits may not have constructor parameters. A trait consists of method and field definition, by mixing them into classes it can be reused.

83.

What Is Recursion Tail In Scala?

Answer»

‘Recursion’ is a function that calls itself. A function that calls itself, for example, a function ‘A’ calls function ‘B’, which calls the function ‘C’. It is a technique used FREQUENTLY in functional programming. In ORDER for a TAIL recursive, the call BACK to the function must be the last function to be performed.

‘Recursion’ is a function that calls itself. A function that calls itself, for example, a function ‘A’ calls function ‘B’, which calls the function ‘C’. It is a technique used frequently in functional programming. In order for a tail recursive, the call back to the function must be the last function to be performed.

84.

Mention The Difference Between An Object And A Class ?

Answer»

A class is a definition for a description. It DEFINES a type in terms of methods and composition of other types. A class is a blueprint of the object. While, an object is a singleton, an instance of a class which is unique. An anonymous class is created for every object in the CODE, it inherits from whatever CLASSES you DECLARED object to implement.

A class is a definition for a description. It defines a type in terms of methods and composition of other types. A class is a blueprint of the object. While, an object is a singleton, an instance of a class which is unique. An anonymous class is created for every object in the code, it inherits from whatever classes you declared object to implement.

85.

What Are The Scala Variables?

Answer»

Values and VARIABLES are two shapes that come in SCALA. A value variable is constant and cannot be changed once assigned. It is immutable, while a regular variable, on the other hand, is mutable, and you can CHANGE the value.

The two TYPES of variables are

var MYVAR : Int=0;
val myVal: Int=1;

Values and variables are two shapes that come in Scala. A value variable is constant and cannot be changed once assigned. It is immutable, while a regular variable, on the other hand, is mutable, and you can change the value.

The two types of variables are

var myVar : Int=0;
val myVal: Int=1;

86.

In What Ways Scala Is Better Than Other Programming Language?

Answer»
  • The arrays uses regular GENERICS, while in other language, generics are bolted on as an afterthought and are completely separate but have overlapping behaviours with arrays.
  • Scala has immutable “val” as a first class language feature. The “val” of scala is similar to Java final variables. Contents may mutate but top reference is immutable.
  • Scala lets ‘if blocks’, ‘for-yield loops’, and ‘code’ in BRACES to return a value. It is more preferable, and eliminates the need for a separate TERNARY operator.
  • Singleton has singleton objects rather than C++/Java/ C# CLASSIC static. It is a cleaner solution
  • Persistent immutable collections are the default and BUILT into the standard library.
  • It has native tuples and a concise code
  • It has no boiler plate code

87.

What Is The Advantage Of Scala?

Answer»

88.

What Is A ‘scala Map’?

Answer»

SCALA map is a collection of KEY or value pairs. Based on its key any value can be RETRIEVED. Values are not UNIQUE but keys are unique in the Map.

Scala map is a collection of key or value pairs. Based on its key any value can be retrieved. Values are not unique but keys are unique in the Map.

89.

What Is A ‘scala Set’? What Are Methods Through Which Operation Sets Are Expressed?

Answer»

SCALA set is a collection of pairwise ELEMENTS of the same type. Scala set does not CONTAIN any DUPLICATE elements. There are two KINDS of sets, mutable and immutable.

Scala set is a collection of pairwise elements of the same type. Scala set does not contain any duplicate elements. There are two kinds of sets, mutable and immutable.

90.

Explain What Is Scala?

Answer»

Scala is an object FUNCTIONAL PROGRAMMING and scripting LANGUAGE for general SOFTWARE applications designed to express solutions in a concise manner.

Scala is an object functional programming and scripting language for general software applications designed to express solutions in a concise manner.