Hi All,
Thanks for the explanation. I have some questions on this. Please help me understand the below
<code>
class coord
{
int x, y; //Instance Variables
public static void main(
String[] args)
{
int z=40; //Local Variable
coord p1,p2;
p1=new coord();
p1.x=50;
p1.y=50;
p2=p1;
p1.x=100;
p1.y=75;
System.out.println("coordinates of p1 are
"+p1.x+","+p1.y);
System.out.println("coordinates of p2 are
"+p2.x+","+p2.y);
}
}
</code>
In the above code,I understand that the variables declared after the class definition is the Instance variable. and the variable 'z' declared inside the main method is the local variable.According to my understanding, this variable will be accessible only inside the main method. Correct me if im wrong.
coord p1,p2;
The above line in the program, is it declaring objects for the class coord?
p1=new coord();
Im not sure what the above line is doing. Is it creating the object p1 of the coord class? but the general syntax for object creation is
<classname> <object name> = new <call to constructor>.
Please explain. Many Thanks