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
How many bytes are a float?
What is a file pointer?
Is list thread safe in java?
What are the two types of java?
List the different types of classloaders in java.
What is object class in java?
What is meant by local variable and instance variable?
How do you delete a list in java?
Is arraylist a class in java?
What are the different types of inheritance in java?
Can we have multiple public classes in a java source file?
what is the significance of listiterator in java?
What is oops in java?
Is list ordered in java?
What are generic methods?