Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pls help me out to solve this question

 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this example from a mock site with some options .... when i tried to compile this its given me compile time error saying identifier expected... for each lines.


1. StringBuffer sb = new StringBuffer("abc");
2. String s = new String("abc");
3. sb.append("def");
4. s.append("def");
5. sb.insert(1, "zzz");
6. s.concat(sb);
7. s.trim();
 
Tusshar Fasate
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should give compile time error as append()
method is not in String class..
 
Rajshekhar Anand
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
even concat method of String need to have argument of type String.


-Gaurav
 
Tusshar Fasate
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yaa Gaurav is right.
Its second compile time error in code
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Poonam Agarwal,
When you post mock questions to the ranch you must also QuoteYourSources.
If you don't add a valid source for this question, it will need to be removed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic