Friday, March 6, 2009

arithmetic operators byte short datatypes

package funds;

public class DiffOpera {

public static void main(String ar[])
/* If we apply arithmetic operation between two operands a and b
the result is always max(int,type of a,type of b) */
// using arithmetic operation
byte b=10;
b=b+1; // error because max(int,short,int)

short s=40;
s=s+1; // error because max(int,short,int)

// The above error in case of byte and short only we will get

int i=20;
i=i+1; // no error because max(int,type of a,type of b)

// using increment decrement
byte b1=++b; // no error because It perform like this (type b1)b1+1;
short s1=++s; // no error
int i1=++i1; // no error



uday_sunny said...

Nice code. I need many programs like this.

Anonymous said...


sowmya katamaneni said...

Good explanation with simple examples..

ChandraSekhar Sannamuri said...

The example is very clear.. Thank you so much for providing these kind of example.

Thanks brother.. :)

Post a Comment