• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about question 14 in assessment test (Java OCA 8 Programmer I Study Guide, Sybex)

 
nick tomer
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I just started reading the book and i am struggling with the following:

In Introduction page XXXVI does the code compiles from question 14 in assessment test?

The code that I see is:




When I try this it doesn't compile but in the answes it says answer DEF.

Please let me know

Thanks

Nick
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nick tomer wrote:When I try this it doesn't compile but in the answes it says answer DEF.

Did you try to compile the code snippet as-is (including the blank line on line5)? If that's the case, I can imagine that the code doesn't compile successfully In order to compile this code snippet successfully, you need to provide code yourself to replace the blank line as mentioned in the question itself "Assuming we have a valid, non-null HenHouse object whose value is initialized by the blank line shown here, which of the following are possible outputs of this application?". There are three correct answers, and pn page XII (bottom) and XIII (top) an excellent explanation is already provided about why the given options answers are correct or incorrect, describing all possible use cases. So it's up to you to write code to implement these use cases and then see if you get the expected output. I'll provide a code snippet to illustrate option F is a correct answer, and it's up to you to do the same for options D and E.

Let's first create a class which implements the HenHouse interfaceAnd then you can create an instance of this class at line5 to replace the blank lineLet's put everything together nowThis code snippet will compile successfully and if you run this code snippet, you'll notice that an exception is thrown at runtime. So option F is definitely a correct answer.

Hope it helps!
Kind regards,
Roel
 
nick tomer
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roel De Nijs

Thanks for your very descriptive answer. I really appreciate it.

I need to get used to the java type of questions which in my opinion are very sneaky.

Now I understand the question !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic