View Single Post
Old 11-30-2012, 09:39 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Nope, what that does is accepts a double from the input, and creates a new instance of Circle providing it with that double.
The only way to modify it (such as taking the radius from another class), is to construct a new instance of circle since there is currently no way to mutate the value of the radius. So if you wanted to create a new circle twice the size of an existing circle, you can use the get method on it: Circle doubleSizeCircle = new Circle(smallerCircleInstance.getRadius());. Now, the current class definition you have for Circle has a package level access to the variables, but I always assume that the variables will be private unless its final.

Edit:
To expand a bit, since the scope of your current circle's radius property is package accessible, you can actually modify it directly:
PHP Code:
Circle c = new Circle();
c.radius 4.2
However, this is not the most ideal since it would also allow me to do:
PHP Code:
c.radius = -4.2
which is not a valid raidus.

Last edited by Fou-Lu; 11-30-2012 at 09:41 PM..
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
CodyJava (11-30-2012)