public class Student {
private String name;
private int age;
public Student() { }
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public String toString() {
return name + "---" + age;
}
}
------------------------------------------------------------------
class StudentDemo{
public static void main(String[] args){
Student s = new Student("zhangsan",27);
System.out.println(s);
}
}
这里输出s时,是不是省略了s.toString( )的写法?创建对象后,调用方法,不应该是对象名.方法名()的格式吗?这是一种默认写法吗?求解
|
|