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
Which is faster string or stringbuilder?
Can we convert list to set in java?
How many unicode characters are there?
Can we create our own daemon thread?
What are the different types of inheritance in java?
How do you use wildcards?
Can a method be static?
What are heterogeneous objects?
How can we make sure main() is the last thread to finish in java program?
How use .contains in java?
When is finally block not called?
Why singleton class is used in java?
What is the purpose class.forname method?
What is increment in java?
Can a method inside a interface be declared as final?