You are on page 1of 3

//wrp to demo operator

class Opr1
{
public static void main(String[] args)
{
int x1=-8;//asignment,- binary
int y1=3;
System.out.println(x1%y1);//-2
}
}

//wrp to demo operator


class Op2
{
public static void main(String[] args)
{
int x=4,y=2;//assignment
x+=++x;//+= multiple assignment,++ unary
//x=x + ++x x=9
y-=y--;
//y=y - y-- y=0
System.out.println(x+" "+y);
}
}

//wrp to demo operator


class Op3
{
public static void main(String[] args)
{
int x=70,y=80,z;
z=(x>y)?1:2;//ternary operators
System.out.println(z);
}
}

//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
}

public static void main(String[] args)


{
show1();
show2();
}
}

//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;

public static void main(String[] args)


{
Var2 obj=new Var2();
System.out.println(obj.x);
System.out.println(obj.y);

}
}

//static variables or class variables


//inside class outside method with "static"
//default values 0,0.0,false
//non-heap memory [stack]
// class loading
//without objects,with classname
class Var3
{
static int x=10;//static variables

public static void main(String[] args)


{

System.out.println(Var3.x);
System.out.println(x);

}
}

You might also like