• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

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

 
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
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • 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 !
 
Ranch Hand
Posts: 94
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I resume this post because I found myself as embaracced as nick.
So, OK, F is definetly a correct answer:

The application will compile but produce an exception at runtime


because if we have an EmptyHenHouse object whose class implements HenHouse, the following line should produce a runtime exception:

and if this assumption is correct so it should be also correct the following answer:

The application will compile but produce any output


But it is not. So why?
Anyone can explain to me?



 
author & internet detective
Posts: 39448
768
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniele,
It's a semantics thing. C and F can't both be correct. Both C and F agree that the code compiles. So far so good. However, C says the code doesn't produce any output and F says the code prints an exception. An exception is output.

And no need to be embarrassed! I'm glad this came up here and now you won't lose points on the distinction on the real exam!
 
Daniele Barell
Ranch Hand
Posts: 94
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Daniele,
It's a semantics thing. C and F can't both be correct. Both C and F agree that the code compiles. So far so good. However, C says the code doesn't produce any output and F says the code prints an exception. An exception is output.


So the Runtime Exception IS the output....I spent so much time in understanding this question, I did understand it but then did it wrong all the same!

Jeanne Boyarsky wrote:And no need to be embarrassed! I'm glad this came up here and now you won't lose points on the distinction on the real exam!


Well if continue this way I really don't know WHEN I will get ready to the real exam...anyway I take it as an encouragement.

Thanks a lot Jeanne.
Have a Pie.
 
Jeanne Boyarsky
author & internet detective
Posts: 39448
768
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniele Barell wrote:So the Runtime Exception IS the output....I spent so much time in understanding this question, I did understand it but then did it wrong all the same!


Correct!
 
It's exactly the same and completely different as this tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!