aspose file tools*
The moose likes Beginning Java and the fly likes Adding bytes and getting int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Adding bytes and getting int" Watch "Adding bytes and getting int" New topic
Author

Adding bytes and getting int

Prakash Rai
Ranch Hand

Joined: Jan 10, 2011
Posts: 101


Q1. If we are adding byte and byte then it should also result byte but it is int. Why?
Abhijeet Sutar
Greenhorn

Joined: Feb 28, 2010
Posts: 17

@Somprakash Rai
First,
Next time, Whenever you want to ask new question, start in new topic.

Second,answer to above question,Whenever the byte ,short and char type variables used in the expression like above one ,addition , those variables are promoted to int type


OCPJP 6 93%
Prakash Rai
Ranch Hand

Joined: Jan 10, 2011
Posts: 101

Abhijeet Sutar wrote:@Somprakash Rai "I think I have started Java Basic topic and all these question comes under this topic so I have posted . "
First,
Next time, Whenever you want to ask new question, start in new topic.


Second,answer to above question,Whenever the byte ,short and char type variables used in the expression like above one ,addition , those variables are promoted to int type
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36486
    
  16
Abhijeet Sutar wrote: . . . Whenever you want to ask new question, start in new topic. . . .
Agree. We have a relatively new feature, which allows me to make the new posts into a new topic.

Voilà!

And I think you have given a sufficient answer.
 
 
subject: Adding bytes and getting int
 
Similar Threads
About cast of int
Primitive assignments - Strange behavior
under what conditions can an int be assigned to a byte?
Doubt in K&B SCJP 5: topic Assignments Pg. 182, 183
int as expression value