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 |
Is main a function?
Difference between an argument and a parameter?
10 Answers Accounting, HCL, IBM, Quinnox,
Name the package that always imported by default?
Define how does a try statement determine which catch clause should be used to handle an exception?
Urgent requirement of JAVA/.NET/QA in a CMMI level3 MNC for Pune location.
How to excute - Interface - Inner class- method can any one tell how to execute/ call this main method public interface abc { static int i=0; void dd(); class a1 { a1() { int j; System.out.println("inside"); }; public static void main(String a1[]) { System.out.println("in interfia"); } } }
Is a method a procedure?
What are the major advantages of internal iteration over external iteration?
What is the use of Getters and Setters method ?
Implement two stacks using a single array.
What's the base class of all exception classes?
What is null data type?