solve this is my problem byte a=40,byte b=50 both add value is 90 this is with in range of byte... byte range is -128to 127....
why this pgm gives error like type mismatch....
package javapgms;
public class byte1 {
public static void main(String args[])
{
byte a=40,b=50;
byte c=a+b;
System.out.println(c);
}
}
note : dont use int k...
a,b,c are in byte range... mind it..
Answers were Sorted based on User's Feedback
Answer / chaya k
There is a complile time error occurs while adding byte variables a and b together. Because we have to know that when we add byte numbers we get int as a resultant datatype.
Here,both a and b are in byte, then resultant datatype after addition is in int datatype but not in byte.We can't store value from int datatype to value in byte datatype so we do down-typecasting as:
byte c=(byte) a+b;
If you don't want to downcaste you should store resultant value in int datatype only as,
int c=a+b;
| Is This Answer Correct ? | 7 Yes | 1 No |
How can constructor chaining be done using this keyword?
Difference between keyword and identifier.
Why string is popular hashmap key in java?
Is string a keyword in java?
printstream class method println() is calling using System class and its static object out .how it is explain any one in detail with example ?
What is the difference between pageContext and page implicit objects in jsp?
9 Answers Gspann Technologies, Merrill Lynch, Polaris,
What is t in generics in java?
Which non-unicode letter characters may be used as the first character of an identifier?
Can variables be used in java without initialization?
what is the output ? Math.floor(-2.1) a)2 b)-2 c)-3.0 d)0
What is meant by javabeans?
Explain the Propertie sof class?