• 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

Jaworski Book Questions

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In chapter 9 of the book, I found these two questions the answers to which, I think are not right. Could someone please clarify.
5. Which of the following methods cause the string object referenced by s to be changed:
A. s.concat()
B. s.toUpperCase()
C. s.replace()
D. s.valueOf()
Answer: A & B
But aren't string objects immutable? I think none of them is correct.

6. What is the output of the following program?
public class Question
{
public static void main(String args[])
{
String s1 = "abc";
String s2 = "def";
String s3 = s1.concat(s2.toUpperCase());
System.out.println(s1+s2+s3);
}
}

A. abcdefabcdef
B. abcabcDEFDEF
C. abcdefabcDEF
D.None of the above
Answer : D
But i think C is correct.

One more question.....are string literals eg: s = "One" garbage collected? If so, when?

Thanx.....
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gopi!
You are right, it's weird answers given in the book.
i checked with the output.
for 2nd question is C only. First Q it's obvious...
cheers
Rajan
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,
I will move this to the Errata forum by the end of the day unless I hear otherwise.
Ajith
 
Gopinath Rajgopal
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why should this be moved?
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'cos it will then be available to other people looking for documented mistakes. That's the purpose of Errata forum.
Ajith
[This message has been edited by Ajith Kallambella (edited August 10, 2000).]
 
Gopinath Rajgopal
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh....thanx Ajith
reply
    Bookmark Topic Watch Topic
  • New Topic