Somethings are strange in this code.
What are these ? :/
1. (public Color color;) : Why it hasn't object?
2. Why in default constructor we use that! :(
Шарох
Level 10
Hi Coders!
Under discussion
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Misiu
12 November 2020, 01:23
Ask authors of the task ;)
There might be:
and empty body of default constructor.
But authors decided their way: reference "color" is done in constructor. +2
Шарох
13 November 2020, 08:33
Thank you Misiu !
So which way is better?
0
Misiu
13 November 2020, 13:50
I don't see difference.
In both cases to use variable "color" (to give it reference other then null) you have to run constructor.
+2
Nouser
11 November 2020, 16:22
That's a field. Field objects by default are initialized with a null reference. And keep in mind you do not store an object in color but a reference to a Color object. The constructor then is used to initialize the field like...
+1