publicclass MainClass {
publicstaticvoid main(String[] argv) {
short s = 259;
byte b = s; // Compiler error
b = (byte) s; // Explicit cast
System.out.println("b = " + b);
System.out.println("s = " + s + ", b = " + b);
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from short to byte
at MainClass.main(MainClass.java:4)