This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

+= operator

 
Raghav Aggarwala
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Here is the question

Which of the following code fragments are legal Java Code?

A.
String A = "abcdefg";
A -= "cde";

B.
String A = "abcdefg";
A += "cde";

C.
Integer J = new Integer(27);
J -= 7;

D.
Integer J = new Integer(27);
J--;


The answer to the above question is B. Explaination: Since String is the only class for which an assignment operator += is defined.
Source: Bill Brogden Exam Cram 2 Sample Test Two

Now I tried compiling option C & D. Both works fine. Are options C and D legal???

Please help..

thank you all,

Raghav
 
sharan vasandani
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes += and -= will work for Integer and += will work for String also.
 
Meena R. Krishnan
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>>are options C and D legal???

In 5.0, Yes.
 
Raghav Aggarwala
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you sharan and krishnan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic