package cn.hpu.animal;
public class CatTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
//对象实例化
Cat one=new Cat("花花",3,"中华田园猫");
Cat two=new Cat();
//测试
// one.eat();
// one.run();
// one.name="花花";
// one.month=2;
// one.weight=2.5;
// two.name="帆帆";
// two.month=5;
// two.weight=3;
System.out.println("昵称"+one.name);
System.out.println("年龄"+one.month);
System.out.println("体重"+one.weight);
// System.out.println("昵称"+two.name);
// System.out.println("年龄"+two.month);
// System.out.println("体重"+two.weight);
//
}
}
package cn.hpu.animal;
/**
* 宠物猫类
* @author Hongliang Wang
*
*/
public class Cat {
//成员属性:年龄,昵称,体重,品种
//注意成员变量的位置:在cat类内,在方法以外。
String name;//String 默认值为null
int month; //i
带参构造方法
最新推荐文章于 2023-09-26 18:56:21 发布