Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in Inquisition

 
Cyril Boulm�
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have tried the test by the Muppeteer in the software Inquisition,
and in question 28 :


Answer :
A/ 0
B/ some garbage
C/ 3
D/ Compilations failed

And it says correct answer is D with no explanation, but I tried it and answer is null!!
Is it an error or something I don't understand?

And in question 27

Consider these 4 statements:

Boolean b = Boolean.parseBoolean("true");
Boolean c = Boolean.valueOf("true");
Float f = Float.valueOf("1011",2);
Every wrapper has a public void toString(); method
How many compilable or true (in case of 4) statements do you see ?


Answer
A/0
B/1
C/2
D/3
E/4


Correct answer is C/2 and explanation is :
The first 2 are true. Via autoboxing 1) goes into the variable. The valueOf returns a Boolean object anyhow. A little trick to remember the return type is: if you hear the primitive in it (pareInt, pareShort, intValue, shortValue...) then it returns a primitive, else an Object


But for me ligne 4 is true too, because every object have a toString() method...
Help
 
fred rosenberger
lowercase baba
Bartender
Posts: 12185
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but does every object have a

public void toString();

method?
 
Daniel Del Moral
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regarding question No. 27:

Every classes hast a public String toString() method from the Object class, hence is impossible that any object can implement a void toString() method because it doesn't override coreectly the toString method (bad return type)
 
Cyril Boulm�
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks for question 27, I have not seen the void

And for question 28? Do you have an explanation?
 
Stevi Deter
Ranch Hand
Posts: 265
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cyril,

Question 28 (which is 14 when I set the test to go in order) looks fine to me and compiles in Java 5 and Java 6. As you found, it prints "null" because the zeroth element is null.

I note no explanation is included for the answer; perhaps you should check back with the test writer and ask him to verify his answer.

It's fine to assign an array of Integers to a Number array reference.
 
Matt Russell
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oik, yeah, question "28" is clearly broken -- thanks for the bug report. It'll be fixed next time Inquisition is released.
 
Stevi Deter
Ranch Hand
Posts: 265
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Matt,
Thanks for doing good work!
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
I give you the explanation why Q28 is giving you null as result.
if you see the Integer hirerachy, it come out to be following:

Object --> Number --> Integer

In array it is perfectly legal to declare:

ParentClass pc = new ChildClas[...];

So
Number na = new Integer[5];

This will declare an array that can hold 5 Integer Object and assign it to na.

Remember the array rule :
"Whenever an Array is declared all its element are initialized with default values"

so it your case, Default value for an Integer Object is null.
so you get na[0] == null
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic