• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

KB Practice Exams - Practice Test 4 Q5

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to everyone,

I have two doubts with the following question,

1. Just to be sure, in line 6 "y" doesn't have a default value (so its null), the only member variables which get a default value are primitives right?
2. Test in line 14 should not print "1" in the first 3 iterations (i=0,1,2), so why the correct answer is C? Can you explain me please? I mean ^ is only true when only one of the tests is true, when i=0 then x=0, then x<2 true and x<10 true, so why does it gets printed?

Thanks in advance
Fernando

 
Ranch Hand
Posts: 47
Redhat Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see image
dfdf.png
[Thumbnail for dfdf.png]
 
Fernando Martinez
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, it was kind of obvious..... :-)
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Fernando Martinez wrote:Thanks, it was kind of obvious..... :-)



Nothing is obvious in these type of questions! The fact that short circuiting doesn't occur at line 14 makes a difference watch out for the || or |!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic