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
Should you use singleton pattern?
What do you know about java?
Can java cast null?
What are the different types of collections in java?
How do you input a string in java?
What is increment in java?
What is the use of object and class classes?
What do you mean by ordered and sorted in collections in java?
How to disable caching on back button of the browser?
What are the two types of java?
Can an interface be defined inside a class?
What are the 7 types of characters?
Can we have try without catch block?
Is boolean a wrapper class in java?
How do you use parseint in java?