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 java command?
What is a function easy definition?
Can inner class have constructor?
What is static method with example?
what are synchronized methods and synchronized statements? : Java thread
How do you achieve polymorphism in java?
What is arrays aslist in java?
What is the use of accept () method in java?
What does percent mean in java?
What is multi-catch block in java?
How do you create an array in java?
What type of variable is error flag?
What is the default access specifier for variables and methods of a class?
Can an interface extend another interface?
What is flush () in java?