Question: Consider the Scala program: def f ( ) : Int = > Unit = { var x: Int = 0 def g ( y: Int

Consider the Scala program:
def f(): Int => Unit ={
var x: Int =0
def g(y: Int): Unit ={ x += y; print(x +",")}
g
}
val h1= f()
h1(3); h1(4)
val h2= f()
h2(3); h2(4)
h1(3); h1(4)
What will happen when the program is executed?
Program self destructs in a puff of smoke.
Prints: 3,4,3,4,
Prints: 3,7,3,7,
Prints: 3,7,10,14,17,21,
Prints: 3,7,3,7,10,14,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!