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


Please Help Members By Posting Answers For Below Questions

What does string mean in java?

630


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?

525


What is meant by inheritance and what are its advantages?

583


What is not thread safe?

496


What is hashmap and map?

560






What is the lifetime and scope of a variable?

520


Which is faster string or stringbuilder?

521


Define the term string pool?

590


What is main difference between variable and constant?

532


what is meant by HQL?

643


What are the different access modifiers available in java?

563


What is scanner in java?

543


How many ways can you break a singleton class in java?

490


Is java code slower than native code?

563


What is a class variable?

573