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 does string mean in java?
I want my class to be developed in such a way that no other class (even derived class) can create its objects. How can I do so?
What is meant by inheritance and what are its advantages?
What is not thread safe?
What is hashmap and map?
What is the lifetime and scope of a variable?
Which is faster string or stringbuilder?
Define the term string pool?
What is main difference between variable and constant?
what is meant by HQL?
What are the different access modifiers available in java?
What is scanner in java?
How many ways can you break a singleton class in java?
Is java code slower than native code?
What is a class variable?