wanglixia 2 days ago
parent
commit
5fcc0cf30f
  1. 0
      w1/AI协助记录.txt
  2. 0
      w1/README.md.txt
  3. 0
      w1/TemperatureConverter.class
  4. 0
      w1/TemperatureConverter.java
  5. 0
      w1/运行成功截图.png
  6. 7
      w6/Animal.java
  7. 28
      w6/AnimalTest.java
  8. 9
      w6/Cat.java
  9. 13
      w6/Dog.java
  10. 5
      w6/Swimmable.java
  11. BIN
      w6/屏幕截图 2026-04-15 200919.png

0
AI协助记录.txt → w1/AI协助记录.txt

0
README.md.txt → w1/README.md.txt

0
TemperatureConverter.class → w1/TemperatureConverter.class

0
TemperatureConverter.java → w1/TemperatureConverter.java

0
运行成功截图.png → w1/运行成功截图.png

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 81 KiB

7
w6/Animal.java

@ -0,0 +1,7 @@
package w6;
public abstract class Animal {
public abstract void makeSound();
}

28
w6/AnimalTest.java

@ -0,0 +1,28 @@
package w6;
public class AnimalTest {
public static void main(String[] args) {
//多态调用Animal抽象类
System.out.println("===动物叫声测试===");
Animal dog1=new Dog();
Animal cat1=new Cat();
dog1.makeSound();
cat1.makeSound();
//多态调用Swimmable接口
System.out.println("\n===游泳能力测试===");
Swimmable swimmer = new Dog();
swimmer.swim();
//数组遍历多态演示
System.out.println("\n===数组多态遍历===");
Animal[] animals={new Dog(),new Cat()};
for (Animal animal :animals) {
animal.makeSound();
if (animal instanceof Dog) {
((Dog) animal).swim();
}
}
}
}

9
w6/Cat.java

@ -0,0 +1,9 @@
package w6;
public class Cat extends Animal {
@Override
public void makeSound() {
System.out.println("喵喵喵");
}
}

13
w6/Dog.java

@ -0,0 +1,13 @@
package w6;
public class Dog extends Animal implements Swimmable{
@Override
public void makeSound() {
System.out.println("汪汪汪!");
}
@Override
public void swim() {
System.out.println("狗刨式游泳");
}
}

5
w6/Swimmable.java

@ -0,0 +1,5 @@
package w6;
public interface Swimmable {
void swim();
}

BIN
w6/屏幕截图 2026-04-15 200919.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Loading…
Cancel
Save