第4章课后作业

第5题 设计Bird 、Fish类,都继承自抽象类Animal,实现其抽象方法info(),并输出他们的信息

/**
 * 动物类
 */
public abstract class Animal {
private int age;

public Animal(int age) {
super();
this.age = age;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public abstract void info();

}

/**
 * 鸟类
 */
public class Bird extends Animal {
private String color;

public Bird(int age, String color) {
super(age);
this.color = color;
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public void info() {
System.out.println("我是一只" + this.color + "的鸟\n今年" + this.getAge() + "岁了!");
}

}

/**
 * 鱼类
 */
public class Fish extends Animal {
private int weight;

public Fish(int age, int weight) {
super(age);
this.weight = weight;
}

public int getWeight() {
return weight;
}

public void setWeight(int weight) {
this.weight = weight;
}
public void info() {
System.out.println("我是一只"+this.weight+"斤重的鱼\n今年"+this.getAge()+"岁了!");
}

}

/**
 * 测试类
 */
public class Test {
public static void main(String[] args) {
Animal animal = new Bird(4,"红色");
animal.info();
Animal animal1 = new Fish(2,5);
animal1.info();
}

}

第6题 兜兜家养了两只家禽:一只鸡和一只鸭,请用面向对象思想的封装和继承的特性进行描述

/**
 * 家禽类
 */
public abstract class Poultry {
private String name;//名字
private String likeFood;//喜爱食物

public Poultry(String name,String likeFood) {
super();
this.name = name;
this.likeFood = likeFood;
}


public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLikeFood() {
return likeFood;
}
public void setLikeFood(String likeFood) {
this.likeFood = likeFood;
}
public abstract void show();

}

/**
 * 鸡类
 */
public class Chicken extends Poultry {
private String strain; //品种

public Chicken(String name, String likeFood, String strain) {
super(name, likeFood);
this.strain = strain;
}
public String getStrain() {
return strain;
}
public void setStrain(String strain) {
this.strain = strain;
}
public void crow() {
System.out.println("我会打鸣!");
}
public void show() {
System.out.println("我叫"+this.getName()+",是一只"+this.strain+"!\n我喜欢吃"+this.getLikeFood()+"!");
this.crow();
}

}

/**
 * 鸭类
 */
public class Duck extends Poultry {
private String type;//类型

public Duck(String name, String likeFood, String strain) {
super(name, likeFood);
this.type = strain;
}

public String getStrain() {
return type;
}

public void setStrain(String strain) {
this.type = strain;
}

public void crow() {
System.out.println("我会游泳!");
}

public void show() {
System.out.println("我叫" + this.getName() + ",是一只" + this.type + "!\n我喜欢吃" + this.getLikeFood()+"!");
this.crow();
}

}

/**
 * 测试类
 */
public class PoultryTest {
public static void main(String[] args) {
Poultry poultry = new Chicken("喔喔", "虫子", "芦花鸡");
poultry.show();
System.out.println("");
Poultry poultry1 = new Duck("嘎嘎", "小鱼虾", "斑嘴鸭");
poultry1.show();
}
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 什么是响应式设计?为什么它很重要? 响应式设计指的是能够自适应不同设备和屏幕尺寸的网站设计。它很重要,因为现在人们使用各种设备来浏览网站,包括电脑、平板电脑、智能手机等等,如果网站不能自适应屏幕尺寸,就会影响用户体验和网站的可用性。 2. 什么是流式布局?它与固定布局有什么不同? 流式布局指的是根据浏览器窗口大小自动调整网页布局的方式。与固定布局相比,流式布局能够更好地适应不同尺寸的屏幕,但是可能会导致一些元素的尺寸和位置不稳定,需要进行适当的调整。 3. 什么是媒体查询?它在响应式设计中起什么作用? 媒体查询是一种CSS技术,可以根据不同设备和屏幕尺寸应用不同的样式。在响应式设计中,媒体查询可以检测屏幕宽度、高度、方向等属性,从而应用不同的样式,实现自适应布局和美观的设计。 4. 什么是断点?在响应式设计中如何使用断点? 断点指的是设定的屏幕尺寸值,根据这些尺寸值来应用不同的样式。在响应式设计中,断点通常用于设置不同的布局、字体大小、图像尺寸等样式,根据不同的屏幕尺寸进行调整,以保持网站的可用性和美观。 5. 什么是流体图像?它在响应式设计中的作用是什么? 流体图像指的是可以自适应不同屏幕尺寸的图像。在响应式设计中,流体图像可以根据屏幕宽度和高度自动调整大小,以保持图像的清晰度和美观度。这可以提高网站的用户体验,并减少加载时间和带宽的消耗。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值