If you need to assign a literal numeric value to a narrower type, and the value is outside that type's range, then you (the programmer) must supply an explicit cast. This is required because you are losing information, which might give undexpected results. By supplying the explict cast, you (the programmer) are saying, "Yes, I understand this could be a problem, but trust me, this is what I want."
Edit: I thought you were asking how to solve the "problem" of getting an unexpected result (which would be to avoid the narrowing cast). But maybe you're asking instead how this result is calculated...? For that, see my follow-up below.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
ankit maini wrote:...
How to solve these types of problems ?
How to identify the sign?
In Java, the integral primitives (byte, short, int, and long) are stored as signed two's complements. See Cornell - Two's Complement.
In your example, the int 3249 is represented as 32-bits, 0000 0000 0000 0000 0000 0000 1011 0001.
When you narrow this to an 8-bit byte, it becomes 1011 0001.
In two's complement, the most significant bit (the one farthest to the left) is the "sign bit." If that's a 1, then the value is negative. So the byte 1011 0001 is negative. As explained by the link above, the absolute value of this negative number is determined by inverting the bits and adding one.
Inverting 1011 0001 results in 0100 1110, and adding 1 results in 0100 1111, which is 79 in decimal. So it's -79.
Marc explains it in detail; you have to know what the bits of the number look like in two's complement to figure out what the result will be exactly.
If you're doing this because you are learning for a certification exam, then you will not get questions like these on the exam. Nobody will expect you to be able to see in your head what the two's complement of an arbitrary integer will look like... but it's important to understand the principle.