• 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

Single choice question has multiple answers

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I got the following code from Whizlab,

which of the following statements is/are true about compiling and running the following code ?



[A] The program comiples correctly and prints "false" and null.
[B] The program will comiple correctly if line 1 is removed
[C] The program will compile correctly if line 2 is removed
[D] The program will compile correctly if line 3 is removed
[E] The program will compile correctly if line 4 is removed
[F] None of above

This test about final reference variable can not assign value more than once. So answer B and E are both correct, but this is a single answer question, which one should I go if similar question appears in real exam?
 
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like the question is designed with careless attitude. If we go by the compiler then the error will be shown at line 4. So you can go for that.

In exam I don't think that there will be questions like this.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only E is the correct answer. Line 1 is OK as it sets the final field for the first time which is allowed...
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This test about final reference variable can not assign value more than once. So answer B and E are both correct



Only E is correct. B is incorrect.
Have you tried to compile the code after line 1 is removed?
It will still not compile. Because line2 is checking instanceof obj, and compiler will give error:

 
Henry Zhi Lin
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Varun,

you are right, as you said the answer is E and once I removed line one the initialization problem comes out. Thanks to point out
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic