Oprs
Oprs
class Opr1
{
public static void main(String[] args)
{
int x1=-8;//asignment,- binary
int y1=3;
System.out.println(x1%y1);//-2
}
}
//byte->short->int->long->float->double
//double->float->int->short->byte
class Op4
{
public static void main(String[] args)
{
short x=70;
int y=x;//type conversion [widening] [small type to long]
//[narrowing] [long type to small type]
int a=5;
short b=(short)a;//narrowing
System.out.println(y+" "+b);
}
}
class Op6
{
public static void main(String[] args)
{
short x=10;
short y=20;
short z=x+y;//error
System.out.println(z);
}
}
class Op7
{
public static void main(String[] args)
{
char x,x1='A';
char y,y1='B';
x=x1++;
y=++y1;
System.out.println(x+" "+y); //A C
}
}
class Op7
{
public static void main(String[] args)
{
int x=20,y=21;
if((++x > 40) || (y-- < 50)) //21>40 || 21<50
System.out.println("good");
else
System.out.println("poor");
}
}
//LOCAL VARIABLES
//inside class,inside method
//no default values
//method area
//no access modifiers
class Var1
{
static void show()
{
int x=10;//local variable
System.out.println(x);
}
static void show2()
{
System.out.println(x);//error
}
//instance variables
//inside class,outside method
//default values 0,0.0,false
//heap memory
// access modifiers allowed
//with objects
class Var2
{
int x=10;//instance variables
int y=20;
}
}
System.out.println(Var3.x);
System.out.println(x);
}
}