A non-boolean primitive data type can be converted to another non-boolean type
if the conversion is a widening conversion.
A non-boolean primitive data type cannot be converted to another non-boolean type
if the conversion would be a narrowing conversion.
publicclass MainClass{
publicstaticvoid main(String[] argv){
double d;
short s;
d = 1.2345;
s = d; // Assign a double value to a short variable
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from double to short
at MainClass.main(MainClass.java:6)