byte and short data types in Java can accept the value outside the range by explicit cast. The higher data types however can not. Why?
<p>Let's consider the following expressions in Java.</p>

<pre><code>byte a = 32;
byte b = (byte) 250;
int i = a + b;
</code></pre>

<p>This is valid in Java even though the expression <code>byte b = (byte) 250;</code> is forced to assign the value 250 to <code>b</code> which is outside the range of the type <strong>byte</strong>. Therefore, b is assigned <strong>-6</strong> and consequently <code>i</code> is assigned the value <strong>26</strong> through the statement <code>int i = a + b;</code>.</p>

<hr>

<p>The same thing is possible with <em>short</em> as follows.</p>

<pre><code>short s1=(short) 567889999;
</code></pre>

<p>Although the specified value is outside the range of <em>short</em>, this statement is legal.</p>

<hr>

<p>The same thing is however wrong with higher data types such int, double, folat etc and hence, the following case is invalid and causes a compile-time error.</p>

<pre><code>int z=2147483648;
</code></pre>

<p>This is illegal, since the range of <em>int</em> in Java is from <strong>-2,147,483,648</strong> to <strong>2147483647</strong> which the above statement exceeds and issues a compile-time error. Why is such not wrong with <em>byte</em> and <em>short</em> data types in Java?</p>
