• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Jxam String question

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider the following piece of code and select the correct statements.
1. Object o = new String("abcd");
2. String s = o;
3. System.out.println(s);
4. System.out.println(o);
a. The following is displayed:
abcd
abcd
b.The code fails to compile at line 1.
c. The code fails to compile at line 2.
d. The code fails to compile at line 4.
e. The code can be made to compile by changing line 1 to the following: String o = new String("abcd");
Ans given is c. But to me it looks like 'e' also correct. I tried by the changing the code and it worked fine.
Anybody is there to agree with me??
This question I took from Jxam.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surya,
Both (c) and (e) are right answers here. However, if you have to choose just one answer, choose the one which is most appropriate ie., (e). On the otherhand, if the question says "select all the right answers" then IMO you should select both (c) and (e).
This question should remind you that, in the actual test you should read all the answers given before choosing one.
Ajith
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeap!
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ajith and Masham,
Thanks for your replies. It is a muliple choice question and I choose c and e but the answer given is only c.
I am an unregistered user so will not be able to open this thread in Mock exam errata.
Once again thanks,
Surya K
reply
    Bookmark Topic Watch Topic
  • New Topic