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 about static nested classes in java?
What does the “static” keyword mean? Can you override private or static method in java?
What is the default value of byte datatype in java?
What is a cup of java?
What is a jagged array in java?
What is the purpose of skeleton and stub?
Explain throw keyword in java?
How can we make a class singleton?
Why are parameters used in functions?
What is an enumeration?
What is structure of java heap? What is perm gen space in heap?
What is the difference between super class & sub class?
Is array passed by reference in java?
What is the file type?
What is the default size of set in java?