小练习
整一个狗的类
- 属性有名字,品种,年龄,性别
- 方法有吃,叫,睡觉,看家
类图
代码
public class Dog {
public String sex = "male";
public String variety = "Husky";
public int age = 3;
public String name = "dooooooogy";
public void eat(String food){
System.out.println(name + "在吃" +food);
}
public void sleep(){
System.out.println(name + "睡得很香");
}
public String bark(){
return "wangwang!";
}
public void watchHouse(){
System.out.println(name + "光荣完成使命");
}
}
tips:只有启动类有main方法