Assignment Operator Example: Adding short by type casting in java

Java Programming Language / Operators in java

1998

Program:

class OperatorExample{
public static void main(String args[])
	{
	short a=10;
	short b=10;
	//a+=b;//a=a+b internally so fine
	//a=a+b;//Compile time error because 10+10=20 now int
	a=(short)(a+b);//20 which is int now converted to short
	System.out.println(a);
	}
}

Output:

20
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.