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 is class level lock ?

816


what is aggregation in java?

791


What does sizeof return?

775


What are static blocks in java ?

857


Explain the difference between abstract class and interface in java?

768


What do you mean by stream pipelining in java 8?

980


What is scope & storage allocation of global and extern variables? Explain with an example

811


What are the advantages of assembly language?

710


What is a java list?

836


Is java call by value?

835


Explain the selection sort algorithm and state its time complexity?

831


What is stringbuffer in java?

825


State the merge-sort principle and its time complexity.

767


How can a gui component handle its own events?

832


Can we define constructor in inner class?

772