1. public class SampleConversion{
  2. public static void main(String[]args){
  3. short s1 = 50;
  4. //valid
  5. int intOne = s1 + 100;
  6. //error: possible lossy conversion
  7. //from int to short 'cause the
  8. //result is int
  9. //short s2 = s1 + 100;
  10. //invalid
  11. //result is converted to int
  12. //byte b1 = 25;
  13. //short s1 = 50;
  14. //byte b2 = b1 + s1;
  15. //valid
  16. //result is long since long
  17. //has higher bits than int
  18. long longOne = 100 + 100L;
  19. //invalid
  20. //int intOne = 100 + 100L;
  21. //valid
  22. int intTwo = 'c' + 5;
  23. //if char and an integer literal
  24. //are both operands in one operation
  25. //and the result is gonna be stored
  26. //in a char variable then, the result
  27. //is gonna be char type
  28. //valid
  29. char character = 'c' + 5;
  30. //invalid
  31. //int intOne = 5;
  32. //char character = 'c' + intOne;
  33. }
  34. }