Wednesday, 22 July 2015

SIMPLE PROGRAMME TO KNOW HOW TO ASSIGN THE VALUE IN VARIABLES OF CLASS FILE.

programme: use of constructor by assigning the value of x in class file and we recall it in another programme.

class file:

public class cons
{
int x;
cons()
{
x=500;
}
void disp()
{
System.out.println(" value of x "+x);
}
}


we assign the value of x now when we recall the value of x it will show 500.

another programme to recall the value of x:

public class cons1
{
public static void main(String args[])
{
cons c=new cons();
c.disp();
}
}

No comments:

Post a Comment