java中public string啥意思

Java是面向对象的编程语言,它其中包含有各种各样的名词,都有着不同的意思。

Java中的string是字符串的意思,当声明了一个字符串变量时,便可以在里面存储数据。

String类

想要了解一个类,最好的办法就是看这个类的实现源代码,来看一下String类的源码:public final class String

implements java.io.Serializable, Comparable, CharSequence

{

/** 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;

/** Cache the hash code for the string */

private int hash; // Default to 0

/** use serialVersionUID from JDK 1.0.2 for interoperability */

private static final long serialVersionUID = -6849794470754667710L;

........

}

从上面可以看出几点:

1)String类是final类,也即意味着String类不能被继承,并且它的成员方法都默认为final方法。

在Java中,被final修饰的类是不允许被继承的,并且该类中的成员方法都默认为final方法。

2)上面列举出了String类中所有的成员属性,从上面可以看出String类其实是通过char数组来保存字符串的。