Question: Consider the Scala definitions: class A { def f ( n: Int ) : Int = if ( n < = 1 ) 1 else
Consider the Scala definitions:
class A
def fn: Int: Int if n else n fn
class B extends A
override def fn: Int: Int printlnn; super.fn
val b: B new B
printlnbf
What happens when this program is compiled and executed?
Options:
The program fails to compile because the recursive invocation of f inside the definition of method f in class A cannot refer to the other class's f method.
The program compiles and runs successfully and prints on separate lines.
The program compiles and runs successfully and prints
The program compiles and runs successfully and prints on separate lines.
The program compiles, but fails at runtime when making a recursive call to f
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
