Can we add two byte variables and assign the result to a
byte variable ?
b=b1+b2 where b,b1,b2 are byte types
Answer Posted / ashish ranjan
No We cannot add two byte variables directly. The reason behind is the operator '+' is used to perform integer operation. so the variables are automatically promoted to the integer when we perform any arithmetic operation.
so we need to typecast the variables
b= (byte)(b1 + b2);
| Is This Answer Correct ? | 15 Yes | 2 No |
Post New Answer View All Answers
Can constructor return value?
What is unicode datatype?
What does file separator do in java?
How can we access some class in another class in java?
What is a blocking method in Java?
what is the purpose of "virtual"?
Can private method static?
What is java reflection api?
What is boolean example?
What is java in detail?
What is string data type?
Why collection doesn’t extend cloneable and serializable interfaces?
How does varargs work in java?
What do you mean by exception handling in Java?
What are advantages and disadvantages of OOPs?