本帖最后由 杨旭 于 2011-12-22 17:59 编辑
- public class Heima01 {
- public static void main(String[] args) {
- Binbin p = new Binbin("lisi",30);
- System.out.println(p);
- }
- }
- class Binbin{
- private String name;
- private int age;
- public Binbin(String name, int age) {
- this.name = name;
- this.age = age;
- }
- public Binbin(String name) {
- this.name = name;
- }
- @Override
- public String toString() {
- return "Binbin [name=" + name + ", age=" + age + "]";
- }
- }
复制代码 Class 类变量名 要大写
打印时 调用toString()方法 所以要重写 Bean里的 toString()方法 |