So, Actually Im still new in Java Programming Language and still learning about casting Data type So in this case, i have a trouble in casting Byte into Short. Can You guys help me??
public class Main {
public static void main(Strings[] args) {
int number = 2;
long updateNumber = number + 2;
System.out.println(updateNumber); //output : 4
}
}
So in this case, i can cast from (int) into (long) Data type normally because (long) data size is bigger than (int). it's the same case as when i trying to cast it from (short) into (int). But why can't i use this concept to casting Data Type from (byte) into (short)?? eventhough (short) has Data size bigger than (byte)??
public class Main {
public static void main(Strings[] args) {
byte number = 2;
short updateNumber = number + 2;
System.out.println(updateNumber); //output : Error
}
}
I guess thats it.. Sorry for the trouble and Thank youu hehe..