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
What does jenkins do?
What is byte [] in java?
What is the difference between int and integer in java?
How do you compare characters in java?
What is java string pool?
What is a layout manager and what are different types of layout managers available in java awt?
How do you define a parameter?
What is class??
Why multiple inheritance is not supported by java?
what do you mean by classloader in java?
What is java console application?
Explain the meaning of java applet.
What is final, finally, finalize?
Can you declare the main method as final?
What is null statement?