How many String objects will be created when this method is invoked?

转载 2012年04月06日 12:03:06
String s="hello";
String s=new String("hello");
how many object and reference is created in heap and pool.

WHAT IS OUTPUT FOR TH FOLLOWING CODE?

public String makinStrings()
{
String s = "Fred";
s = s + "47";
s = s.substring(2, 5);
s = s.toUpperCase();
return s.toString();
}
How many String objects will be created when this method is invoked?
A. 1
B. 2
C. 3
D. 4
E. 5

F. 6


Thanks a lot Ian and Abhijeet for your exlanation.
When I went through the link given by Ian,
I came across a thread , the reply given by Jim Yingst (wanderer Member # 290) was valuable.Thanks to Jim


"foo", "99" (two objects)created when class is loaded.
"foo99", "o99", "O99" (three objects) created when the method is run.

Since the question has been asked that how many objects will be created when the method is invoked?
The answer is 3.


Thank you guys!!




Method public java.lang.String org.hibernate.exception.NestableRuntimeException.getMessage(int

Method public java.lang.String org.hibernate.exception.NestableRuntimeException.getMessage(int) thre...
  • sun_shine_girl
  • sun_shine_girl
  • 2016年05月15日 18:09
  • 1083

SCJP考题6

930. What String instance method would return true when invoked like this?a.method(b);Where a="GROUN...
  • wangjun_pfc
  • wangjun_pfc
  • 2007年10月13日 15:07
  • 1633

Fatal error occurred when node tried to create too many dynamic partitions

Diagnostic Messages for this Task: Error: java.lang.RuntimeException: org.apache.hadoop.hive.ql.meta...
  • AnneQiQi
  • AnneQiQi
  • 2016年08月24日 10:51
  • 1626

Hashmap源码解析 keyset,entryset

Hashmap源码解析 keyset,entryset HashMap 继承于AbstractMap, 同时实现了Map接口:属于Map的子类。 Cloneable接口:可以被复制。 Seri...
  • ZXC641483573
  • ZXC641483573
  • 2018年01月10日 17:14
  • 22

HDU:1213 How Many Tables(简单并查集)

How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)...
  • zugofn
  • zugofn
  • 2016年08月01日 20:20
  • 543

uva 10061 How many zero's and how many digits ?(在bas进制下分解因子)

挺好的一道数论题。
  • u011328934
  • u011328934
  • 2013年07月26日 16:20
  • 2545

HDU 1213 How Many Tables (并查集,连通分支数,两种方式)

How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)...
  • hurmishine
  • hurmishine
  • 2016年06月09日 23:12
  • 3349

UVA11038 How Many O's?题解

原文链接:http://www.algorithmist.com/index.php/User:Sweepline/UVa_11038.cpp AC的C++语言程序如下: // C++...
  • tigerisland45
  • tigerisland45
  • 2018年01月16日 22:06
  • 94

uva 10061——How many zero\'s and how many digits ?

题意:这道题开始是卡了很久的,题意是给定一个数n然后让你求B进制下n!有多少个零,和有多少位数,咋一看,是高精度,如果数论不是很熟系。思路:开始是直接抛弃高精度的一来是存不下,二来没办法短时间计算出来...
  • bobodem
  • bobodem
  • 2015年10月26日 17:08
  • 251

java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLog

java.lang.LinkageError: loader constraint violation,slf4j日志异常: java.lang.LinkageError: loader c...
  • king624498030
  • king624498030
  • 2015年05月05日 12:46
  • 2420
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:How many String objects will be created when this method is invoked?
举报原因:
原因补充:

(最多只允许输入30个字)