OK my understanding of the phrase:
The class must have a constructor that takes a weight and color as arguments, and initializes all variables except the name and address.
Meant to create something like:
Cat(int weight, String color)
this.color = color;
this.weight = weight;
age = 5;
.. etc.
EXCLUDING address and name since it's not supposed to be "initialized"
However, I couldn't get my code to verify without putting:
this.name = null;
So clearly, I have no idea what initialize means.
Meaning of initialize?
Resolved
Comments (6)
- Popular
- New
- Old
You must be signed in to leave a comment
Anton Kashnikov
4 February 2019, 15:06
Show your full code, please
0
bri
4 February 2019, 15:10
I can't since I have verified it succesfully. I just didn't understand why it worked the way it did.
0
Anton Kashnikov
4 February 2019, 15:13
i think, u initialized field name in another place, so after creating object with this constructor, name was not null (default value of String)
0
bri
4 February 2019, 15:16
So for example if in the top of my code I had written (before constructors)
String name = "Mary";
Then later on I'd have to write null to prevent the name Sally from being written since we don't know the name of the homeless cat for example?
0
Anton Kashnikov
4 February 2019, 15:47
Exactly! Fields initializing in constructor take place after initializing in the creation moment. So, when u don't assign value to variable in constructor, variable get value from earlier context
0
bri
4 February 2019, 15:56
Thanks so much Anton - that makes so much sense I don't know why I wasn't seeing that before, guess that's what happens when blindly entering code!
+3