Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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



solve this is my problem byte a=40,byte b=50 both add value is 90 this is with in range of byte... b..

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

solve this is my problem byte a=40,byte b=50 both add value is 90 this is with in range of byte... b..

Answer / siva

c=(byte)(a+b);

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What are the differences between unchecked exception, checked exception, and errors?

2 Answers  


different between exception and error? explaim check and uncheck exception

4 Answers  


What is linkedlist in java?

0 Answers  


Can an interface be defined inside a class?

0 Answers  


How do constructors use this() and super()?

0 Answers  


What is an example of character?

0 Answers  


Java violates few objected oriented concepts. Can you explain in what way?

3 Answers   Ness Technologies,


A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.

0 Answers  


What are different types of arrays?

0 Answers  


What class of exceptions are generated by the java run-time system?

0 Answers  


How do I remove a character from a string in java?

0 Answers  


Does java list allow null?

0 Answers  


Categories