I found the following question in the book "OCP 11 Practice Tests" by Jeanne Boyarsky & Scott Selikoff (page 9, question 24):
"How many of the following lines compile?
bool b = null;
Bool bl = null;
int i = null;
Integer in = null;
String s = null;
In the appendix (page 444) it is specified that the correct result is C (because Integer and String are objects). What if we have a class called Bool? then "Bool bl = null" is correct, and compiles. I understand that bool cannot be used instead of "boolean" but Bool can represent a class (not "Boolean" of course). Isn't the correct answer D?
I'm a little confused, please help me understand
I think here, you are not allowed to make that assumption, as long as it's not given to you by the question. So it is not correct to assume there is a call class named Bool.
Just like the IO questions where it involves `mark()` method, you can't assume the system support `mark()`, unless the question deliberately tells you that, or if you see `markSupported()` method in the code.
Thank you for your replay!
I read from the book "OCP 11 Study Guide -Programmer I", that: "reference types can be assigned null, which means they do not currently refer to an object. Primitive types will give you a compiler error if you attempt to assign them null" (Boyarsky & Selikoff, p. 45). In this example, "Bool bl = null;" bl variable is a reference of type Bool, I think ...
I would agree with you, if the question given to me is something like this:
So here the question gave you a hint, that a class named "Bool" actually exists. so "Bool bl = null" will compile.
But in the original example, it obviously trying to trick you into selecting the right types and correct declaration.
Bottom line, "Bool" is not a correct type, ti would be correct only and only if there is actually a class named "Bool", which is not a given information in this particular question. So i would say "Bool bl = null" does not compile.