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

Which is faster string or stringbuilder?

503


Can we convert list to set in java?

497


How many unicode characters are there?

537


Can we create our own daemon thread?

520


What are the different types of inheritance in java?

515






How do you use wildcards?

516


Can a method be static?

513


What are heterogeneous objects?

556


How can we make sure main() is the last thread to finish in java program?

651


How use .contains in java?

606


When is finally block not called?

569


Why singleton class is used in java?

553


What is the purpose class.forname method?

544


What is increment in java?

509


Can a method inside a interface be declared as final?

510