package mianxiangduixiang; //猫 public class cat { private String name; private String color; private int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } //行为 //显示名字 private void showName() { System.out.println("猫的名字是"+this.name); } //叫一声 private void shout() { System.out.println("喵...."); } //构造方法 public cat(String name, String color, int age) { super(); this.name = name; this.color = color; this.age = age; } public cat(String name) { super(); this.name = name; } public static void main(String[] args) { cat cat1 =new cat("妮妮"); cat1.setColor("灰色"); cat1.setAge(2); System.out.println("这只猫叫"+cat1.getName()+"颜色是"+cat1.getColor()); System.out.println("这只猫叫"+cat1.getName()+"年龄是"+cat1.getAge()+"岁"); } }
输出猫的名字和颜色
输出猫的名字和年龄