|
Subject:
|
Chapter 5 page 196- duplicating objects
|
|
Posted By:
|
sasman23x
|
Post Date:
|
1/30/2004 12:19:38 PM
|
Hi there. I simply don;t understand how the exmaple works in the book for duplicating objects. the code is
Sphere(final Sphere oldSphere) { raduis= oldSphere.radius; xCenter = oldSphere.xCenter; yCenter = oldSphere.yCenter; zCentre = oldSphere.zCenter;
}
I have anumber of questions 1) is this a constructor 2) how manay arguments have been sent to this (as there are no commas is this one or three) 3) why is the word final there?
|
|
Reply By:
|
Martyn
|
Reply Date:
|
1/31/2004 8:09:37 AM
|
1) Yes, it is a constructor. The fact that it has the same name as the class and doesn't have a return type would indicate this.
2) There is only one argument, it is called oldSphere and its type is a Sphere, which has been declared final.
3) The use of final in this example has been done to ensure that the object reference for oldShpere cannot be modified. It isn't stritcly necessary in an example this trivial, but I'm assuming that Ivor did do so to showcase another use of the final keyword, this time with method parameters and also to indicate good programming style, as he is clearly stating that the original object reference cannot be changed in this constructor.
I hope this helps
Cheers
Martyn
|