Showing posts with label instanceof. Show all posts
Showing posts with label instanceof. Show all posts

Monday, 28 November 2011

Operators and assignments

Using operators - 1


Assignment operators


You can assign a primitive variable using a literal or the result of an expression. The result of an expression involving integers (int, short, and byte) is always at least of type int. Narrowing conversions are not allowed, as they would result in the loss of precision. For instance:

byte b = 5;
byte c = 4;
byte d = b + c;               // does not compile because int cannot fit in a byte


float f = (float)35.67;   // implicitly double, so casting to float
float f = 35.67F;


A boolean cannot be assigned any type other than boolean.

If we assign an existing object reference to a reference variable, both reference variables refer to the same object. It is legal to assign