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 is class level lock ?
what is aggregation in java?
What does sizeof return?
What are static blocks in java ?
Explain the difference between abstract class and interface in java?
What do you mean by stream pipelining in java 8?
What is scope & storage allocation of global and extern variables? Explain with an example
What are the advantages of assembly language?
What is a java list?
Is java call by value?
Explain the selection sort algorithm and state its time complexity?
What is stringbuffer in java?
State the merge-sort principle and its time complexity.
How can a gui component handle its own events?
Can we define constructor in inner class?