Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lessons;
- public class ConversionBetweenPrimitiveDataTypes
- {
- public static void main(String[] args)
- {
- //ex 1
- int x;
- double y = 2.5;
- //x = y;
- //ex 2
- int a ;
- short b = 2;
- a = b;
- // can go bec 2 is also an int, int and shorts are both whole, ints can hold more
- // highest to lowest: double, float long int short byte
- // can only go from lower ranks to higher
- //lower to higher rank conversion is widening conversion
- //higher to lower rank conversion is narrowing conversion
- //widening conversion
- double k;
- int m = 10;
- k = m;
- //strictly typed language: the data type inserted in values must be the same data type as variable
- }
- }
Add Comment
Please, Sign In to add comment