Can we add two byte variables and assign the result to a
byte variable ?
b=b1+b2 where b,b1,b2 are byte types
Answers were Sorted based on User's Feedback
Answer / rajesh
Yes,the following is the right way to do so
byte b1=21;byte b2=11;
byte b;
b=(byte)(b1+b2);
| Is This Answer Correct ? | 39 Yes | 5 No |
Answer / m. abhishek
yes, but u require type casting because the the binary
operation in java should atleast returns Integer values
example :
byte a=12;
byte b=23;
// byte c=a+b; //Not OK,bcoz a+b is an int value
int c=(byte)a+b; // OK
| Is This Answer Correct ? | 34 Yes | 7 No |
Answer / 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 |
Answer / guest
yes.But you have to cast that variable before adding.
eg:
byte b=(byte)b1+(byte)b2
| Is This Answer Correct ? | 7 Yes | 35 No |
What is :: operator in java 8?
Difference between Preemptive scheduling vs. Time slicing?
What about interthread communication and how it takes place in java?
What is lossy conversion in java?
what is platform dependent translation and platform dependent programming language
What is difference between adapter class and listener?
What is difference between equals and hashcode method?
Give few difference between constructor and method?
Can we declare an interface as final?
What is object cloning in Java?
0 Answers SwanSoft Technologies,
How many types of packages are there in Java?
How many boolean functions are there?