How is nr3 "easy" ? Its the hardest on this page.
Anyways. Joshua Bloch says, cloning like this is a bad idea. You should rather use Copy constructors and factories. So its probably not worth spending tooooo much effort on this topic.
For the "Prevent cloning" task ask yourself - when you're trying to clone C, if you can't use super.clone() from B class (as this will return an error), what source of information can you use for the new clone?
And in B class, if you're not supposed to clone this class, what should you return?
I solved it in about 80 minutes, 41 attempts and many google searches without results because it is a very specific situation so I ended up using the mentor solution. But it was a good exercise, because all of the googling and trying to understand the task made me learn new things and better understand the cloning thingy/situation.
Co Pilot helps ; -- and reads me the debug via audio ... of course supplemental info. Codegym is a totally great platform and I have been here for 4 years. My 2nd lap around since I didn't finish .... tenacity for the win )
GO TO FULL VERSION