• 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

q on Stringbuffers

 
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Choose the correct two solutions.
public class Test
{
public static void main(String args[])
{
StringBuffer str1="Hello";
StringBuffer str2=" there";
StringBuffer str3=str1+str2;
System.out.println(str3);
}
}

StringBuffer variables cannot be initialized in this fashion

Compiles & Prints "Hello there"

'+' operator cannot be used for StringBuffer variables.

Compiler converts StringBuffer variables to Strings & performs
initialization & concatenation.

I answered 1st and the 3rd options, but the 2nd option is said to be correct?
can somebody tell me y?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did the question come from?

And please use tags!
 
JayaSiji Gopal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

In my search for SCJP exams on google, I came across this URL.

http://www.geocities.com/sunjava4u/guide.html

In this site, there are a no of downloadable mock exams. All the questions that i posted in the last two days were from this exam.

Regards!
Jayashree.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Option 2 is incorrect because it does not compile because of Option 1. If you fix the error of Option 1 in the obvious way, then it fails as in Option 3.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic