java基础,帮看一下,有不明的地方

shaluoshuangshu 2010-06-05 02:15:30
下面是String类的部分属性和方法;

public final class String{

/** The value is used for character storage. */
private final char value[];

/** The offset is the first index of the storage that is used. */
private final int offset;

/** The count is the number of characters in the String. */
private final int count;


<input type="checkbox" name="public String(String original) {
int size = original.count;
char[] originalValue = original.value;
char[] v;
if (originalValue.length > size) {
// The array representing the String is bigger than the new
// String itself. Perhaps this constructor is being called
// in order to trim the baggage, so make a copy of the array.
int off = original.offset;
v = Arrays.copyOfRange(originalValue, off, off+size);
} else {
// The array representing the String is the same
// size as the String, so no point in making a copy.
v = originalValue;
}
this.offset = 0;
this.count = size;
this.value = v;
}" value="">

}

然后String s1=new String("hello");这个应该调用的是public String(String original) 方法吧?
有几个部分看不懂:
1.public String(String original) ;这个构造方法放在标签里干什么?
2.count\value等属性都是私有的,为什么original.count、original.value在直接调用他?


...全文
113 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
直接建立实例调用就是了
xx314327475 2010-06-05
  • 打赏
  • 举报
回复
你建立了一个String类的实例,然后调用String的方法和属性,不是很正常么?
危险的大猫 2010-06-05
  • 打赏
  • 举报
回复
类内部的方法本来就可以调用本类的属性
xiaoqiao_82 2010-06-05
  • 打赏
  • 举报
回复
是String类的实例在调用它吧:)
一个成员既然能被本实例直接访问,自然也能被同类的其他实例直接访问。

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧