Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how many objects are created by this statement

 
Saravanakumar Rajmohan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how many objects are created by this statement?
System.out.println( "Hi everyone" + 3 );
String object representing "Hi everyone"
Wrapper object for representing the primtive value 3(is this required ?)
String object representing the value 3
String object representing "Hi everyone3"
is this correct or will this undergo optimisation(will it involve StringBuffer)? .
will this have a constant behavior in all JVM implementations
can somebody explain this
thank u
Saravanakumar R
 
Calvin Yan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I think the created objects should include "Hi everyone" and "Hi everyone3"
 
Ted Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this scenario, Two objects was created,
1. "Hi everyone"
2. "Hi everyone3"
Wrapper object is not needed in this case. The concatenation method of String class can accept an integer primitive.
 
sherry cuenco
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there are three objects created.
1 "Hi everyone"
2 "3" // Java converts int 3 to a String
3 "Hi everyone3"
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic