What will be the result of following code execution?
object Main extends App {
  def quiz = {
    val result = 5
       + 6
The function will be interpreted as following:

  def quiz = {
    val result = 5;
    + 6
The result will be last line: +6
  • One issue with Scala‚Äôs semicolon convention is how to write expressions that span several lines. For instance
    + someOtherExpression
    would be interpreted as two expressions:
    + someOtherExpression
    To overcome this problem you could write the multi-line expression in parentheses, because semicolons are never inserted inside (...):
    + someOtherExpression)
    Source: Coursera: Blocks and lexical scope

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback