DogDog

文章展示了两个Java类,Dog1和DogText。Dog1类定义了狗的性别、名字、颜色和叫声属性,并提供了对应的getter和setter方法,以及introduce和bark两个方法来描述狗的信息和模拟叫声。DogText类在main方法中创建了Dog1类的实例,输出了狗的介绍和叫声。
摘要由CSDN通过智能技术生成


public class Dog1 {
		private String sex;
		private String name;
		private String color;
		private String voice;
		public String getSex() {
			return sex;
		}
		public void setSex(String sex) {
			this.sex = sex;
		}
		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 String getVoice() {
			return voice;
		}
		public void setVoice(String voice) {
			this.voice = voice;
		}
		public String introduce() {
			return sex+"狗"+name+"是"+color+"色的";
		}
		public String bark() {
			return sex+"狗"+name+"正在"+voice+voice+voice+"叫";
		}
		
		public Dog1() {}
		
		
		public Dog1(String sex, String name, String color) {
			this.sex = sex;
			this.name = name;
			this.color = color;
		}
		public Dog1(String sex, String name, String color, String voice) {
			this.sex = sex;
			this.name = name;
			this.color = color;
			this.voice = voice;
		}
		
		
	}

public class DogText {
	public 	static void main(String[] args) {
		Dog Dog1=new Dog("母","lili","绿");
		String introduce=Dog1.introduce();
		System.out.println(introduce);
		Dog Dog2=new Dog("公","biubiu","肤色","汪汪叫");
		String bark=Dog2.bark();
		System.out.println(bark);
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值