Конструкторы. Создание объектов класса

class Sphere {

static final double PI=3.14;

static int count = 0;

// поля

double radius;

double xCenter;

double yCenter;

double zCenter;

//конструктор

Sphere (double theRadius, double x, double y, double z)

{

radius = theRadius;

xCenter = x;

yCenter = y;

zCenter = z;

++ count;

}

//методы

static int getCount ()

{

… return count

}

double volume ()

{

return 4.0/3.0*PI*radius*radius;

}

}

1) Sphere ball 2) ball = new Sphere (10.0, 1.0, 1.0, 1.0); 3) Sphere ball2=new Sphere (10.0, 1.0, 1.0,1.0); 4) Sphere ball3=new Sphere (20.0, 2.2, 3.3,4.4); 5) Sphere myBall = ball2; 6) ball3 = null;

Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: