• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jxam question errata

 
Arif Attar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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);

##ans1##
The following is displayed:
abcd
abcd
##ans2##
The code fails to compile at line 1.
##ans3##
The code fails to compile at line 2
##ans4##
The code fails to compile at line 4.
##ans5##
The code can be made to compile by changing line 1 to the following:
String o = new String("abcd");
the answer given is 3). but i think 5) is also correct.
tell me.
bye
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Arif,
You're right
The code fails to compile at line #3; but if you change line #1 to <code>String o = new String("abcd")</code> it will compile.
Just an FYI, the code will also compile if you change line #2 to <code>String s = o.toString();</code>
Hope that helps.
Jane
 
Arif Attar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jane,
Arif
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic