Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PrimitiveAssignments {
- public static void main(String[] args) {
- short sh = 300; // by default integer literals are int
- short sh1 = 127 * 5; // By default a result of an expression is an int
- //short sh2 = 127 * 1000; Does not compile because the int returned does not fit in a range of short
- short sh3 = 5;
- short sh4 = 127;
- //short sh5 = sh3 * sh4; //Does not compile because the value of a variable can change at runtime, needs a cast
- short sh5 = (short)(sh3 * sh4); // Works fine using casting.
- }
- }
Add Comment
Please, Sign In to add comment