• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

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: 9711
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
 
crispy bacon. crispy tiny ad:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic