When Cindy’s statement is entered into the code, BlueJ™ will not compile, stating it “cannot find symbol - constructor Robot()”. This is because the no-args constructor Robot() does not exist. While the code does contain a public method named “Robot”, it requires parameters for the variables mem, mk, mod, and feature. If Cindy were to enter in parameters for each of these variables—requiring one int, two String, and one boolean value, respectively—there would be no error. Cindy could also place “public Robot() {}” into the code. However, this would not create the desired robot; rather, it would simply prevent an error statement.
−Phoenix
Hi Phoenix,
ReplyDeleteI had some errors in the original post to this challenge and your response brought that to my attention. Check it again as I have now corrected things. Thank you.
When Cindy’s statement is entered into the code, a compiler error will not occur. However, the “Robot” object “hal” is of the no-args “Robot” class; therefore, it is a “Robot” object that lacks any parameters. The ideas of memory capacity, manufacturer, model number, and remote disabling features don’t apply. In essence, “hal” is a “Robot” object with “null” instance variables.
ReplyDelete−Phoenix
Are all instance variables null, or just some? If they're not null, what are their values in each case?
ReplyDeleteThe “Robot” object “hal” has no parameters. Therefore, all of the instance variables formed in the code are “null”.
ReplyDelete−Phoenix
Because they are not defined, the “int” variable “memoryCapacity” is set to 0, the “String” variables “make” and “model” are set to “null”, and the “boolean” variable “hasRemoteDisableFeature” is set to “false”.
ReplyDelete−Phoenix
Perfection. It's important to know the default values for each of the data types. Good catch. 50 XPs awarded for completion.
ReplyDelete