Hi All,

scala> def g():Unit={
     | max(3)
     | def max(x:Int){
     | println(x)
     | }
     | }
<console>:6: error: block must end in result expression, not in definition
       }
       ^
Now when you see this you will expect that at the end of max block you will
have to give some expression to evaluate...but i had given it earlier.

scala> def g():Unit={
     | max(3)
     | def max(x:Int){
     | println(x)
     | }
     | max(9)
     | }
g: ()Unit

Now here i give an expression for g():Unit
scala> g
3
9

Now the answer is interesting...it  evaluates the upper expression also.Look
at the order also..Why??.


Another query is a "def" or "a method as in java" automatically returns the
value..(No need to give explicit return) "The value evaluated recently"..So
once it returns a value How can it again evaluate max(3) ????
I mean how can we have two returns.

thanks,

SMS


[Non-text portions of this message have been removed]

Reply via email to