Defining variables in scala using def
<p>In scala def is used to define a method and val, var are used for defining variables.</p>

<p>Consider the following code:</p>

<pre><code>scala&gt; def i = 3
i: Int

scala&gt; i.getClass()
res0: Class[Int] = int

scala&gt; val v = 2
v: Int = 2

scala&gt; v.getClass()
res1: Class[Int] = int

scala&gt; println(v)
2

scala&gt; println(i)
3

scala&gt; i+v
res4: Int = 5

scala&gt; def o = () =&gt; 2+3
o: () =&gt; Int

scala&gt; o.getClass()
res5: Class[_ &lt;: () =&gt; Int] = class $$Lambda$1139/1753607449
</code></pre>

<p>Why does variable definition work using <code>def</code>? If it is defining a function that returns an <code>Int</code> then why does <code>getClass</code> show <code>Int</code> instead of a function object?</p>