From what I gather as a Java beginner, when accessing instance members, the "this" keyword may apparently be used.
see this program,
class sphere{
static final double PI=3.142;
static int count=0;
double radius,xcentre,ycentre,zcentre;
sphere(){
xcentre=0.0;
ycentre=0.0;
zcentre=0.0;
radius=1.0;
count++;
}
sphere(double xcentre,double ycentre,double zcentre){
this(); // what does this mean ??
this.xcentre=xcentre;
this.ycentre=ycentre;
this.zcentre=zcentre;
count++;
}
sphere(double r2, double x, double y, double z){
this(x,y,z); // and what does this mean ??
radius = r2;
}
public static int getcount(){
return count;
}
double volume(){
return ((4.0/3.0)*PI*radius*radius*radius);
}
}
class SphereTest{
public static void main (String args[]){
System.out.println ("Number of Objects: " + sphere.getcount());
sphere ball = new sphere(4.0,1,1,1);
System.out.println (ball.volume() + " " + sphere.getcount() );
}
this();
what does this mean ??
and what does this mean this(x,y,z);
also when i am running this program the object count is 2, why the count is 2 since i've created a single object?