I don't know what am I missing , may be its something minor, but here is the problem
println() is being called out of order. i.e. Output that I get is
Line two.
Line one
Shouldn't it be reversed?
I do know that that "Line two" is out of main method, but what is the reason, I tried searching, but couldn't get to the bottom.
object oneToTen {
def main(args: Array[String]): Unit = {
println("Line one")
}
println("Line two.")
}
In Scala, everything that is in the body and that is not a variable declaration is part of the constructor.
As oneToTen is a scala object, an instance of it is created and then the main method is invoked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With