Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

OCP JAVA SE11 PRACTICE TESTS (Sybex) Chapter 1 - Question 24/page 9

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone!
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;

A. None
B. One
C. Two
D. Three
E. Four
F. Five"

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

Thank you!
Roxana
 
Greenhorn
Posts: 8
1
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roxana,

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.


I hope I'm not wrong lol
 
Roxana Pat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Raoof!
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 ...
Roxana
 
Raoof Aldabil
Greenhorn
Posts: 8
1
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Roxana Pat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow, Raoof! Thank you very much for the explanations and for your help! Now things are clear !!!
Roxana
 
Raoof Aldabil
Greenhorn
Posts: 8
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
author & internet detective
Posts: 41184
848
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raoof is correct. Have a cow for the excellent explanation!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic