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

How many bytes are a float?

513


What is a file pointer?

521


Is list thread safe in java?

497


What are the two types of java?

526


List the different types of classloaders in java.

509






What is object class in java?

511


What is meant by local variable and instance variable?

604


How do you delete a list in java?

541


Is arraylist a class in java?

542


What are the different types of inheritance in java?

537


Can we have multiple public classes in a java source file?

562


what is the significance of listiterator in java?

628


What is oops in java?

575


Is list ordered in java?

550


What are generic methods?

539