举个例子,
class Student{
//学生类的一些定义
}
class Test{
public static void main(String[] args){
Student s = new Student();
System.out.println(s);
System.out.println(s.toString());
}
扫描二维码关注公众号,回复:
1105433 查看本文章
}
输出为
cn.itcast.Student@3b896429
cn.itcast.Student@3b896429
该如何理解这2个输出呢?
System是java.lang里面的一个类;
out就是System里面的一个静态数据成员,而且这个成员是java.io.PrintStream类的引用。如下图,被关键字static修饰的成员可以直接通过"类名.成员名"来引用,而无需创建类的实例。所以System.out是调用了System类的静态数据成员out。