Java short keywordThe Java short keyword is a primitive data type. It is used to declare variables. It can also be used with methods. It can hold a 16-bit signed two's complement integer. Points to remember
![]() Examples of Java byte keywordExample 1Let's see an example to use short data type with positive and negative value. Output: num1: 10 num2: -10 Example 2Let's see an example to check whether the short data type holds decimal value. Output: error: incompatible types: possible lossy conversion from double to short Example 3Let's see an example to check whether the short data type holds float value. Output: error: incompatible types: possible lossy conversion from float to short Example 4Let's see an example to check whether the short data type holds char value. In such case, the compiler typecast the character implicitly to short type and returns the corresponding ASCII value. Output: num: 97 Example 5In this example, short data type holds the minimum and maximum value. Output: min: -32768 max: 32767 Example 6Let's create a method that returns a short type value. Output: 10
Next TopicJava Keywords
|