示例
public class Hero {
public String name;
public int age;
public String color;
public Hero(String name, int age, String color) {
this.name = name;
this.age = age;
this.color = color;
}
public void showInfo() {
System.out.println("我叫" + this.name);
System.out.println("我的年龄" + this.age);
System.out.println("我的颜色" + this.color);
}
}
调用
public class Test4 {
public static void main(String[] args) {
Hero xq = new Hero("大卫",16,"蓝色");
xq.showInfo();
}
}