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 dot operator?
How will you serialize a singleton class without violating singleton pattern?
Does variable declaration allocate memory?
Can we have multiple classes in single file ?
Compare java and python.
How do you find the maximum number from an array without comparing and sorting?
What is the public field modifier?
What are three ways in which a thread can enter the waiting state in java programming?
What is the use of optional ?
Explain some best practices you would apply while using collection in java?
What are constants and how to create constants in java?
What is the disadvantage of java?
What is the difference between a method and a procedure?
When does an object becomes eligible for garbage collection in java?
How to find the index of the largest number in an arraylist java?