This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

q on Stringbuffers

 
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!