Select all correct invocations of the given function:
def sum(x: Int, y: Int = 0) = x + y
Explanation
Get an explanation when it's available:
Theory
  • In any method invocation in Scala in which you're passing in exactly one argument, you can opt to use curly braces to surround the argument instead of parentheses.
    For example, instead of:
      scala> println("Hello, world!")
      Hello, world!
    
    You could write:
      scala> println { "Hello, world!" }
      Hello, world!
    
    This curly braces technique will work, however, only if you're passing in one argument. Here's an attempt at violating that rule:
      scala> val g = "Hello, world!"
      g: java.lang.String = Hello, world!
      
      scala> g.substring { 7, 9 }
      <console>:1: error: ';' expected but ',' found.
             g.substring { 7, 9 }
                            ^
    
    Read more: Writing new control structures

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Scala
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты