From e5190123df516de4de6651b0aac51c3a2a5a073b Mon Sep 17 00:00:00 2001 From: peisishuang <1767255628@qq.com> Date: Tue, 7 Apr 2026 11:18:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 基础题-Shape.txt | 30 ++++++++++++++++++++++++++++++ 挑战题—Person.txt | 20 ++++++++++++++++++++ 进阶题-Vehicle.txt | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 基础题-Shape.txt create mode 100644 挑战题—Person.txt create mode 100644 进阶题-Vehicle.txt diff --git a/基础题-Shape.txt b/基础题-Shape.txt new file mode 100644 index 0000000..f12f6d9 --- /dev/null +++ b/基础题-Shape.txt @@ -0,0 +1,30 @@ +基础题—Shape类 + +class Shape { + public void draw() { + System.out.println("绘制形状"); + } +} +class Circle extends Shape { + @Override + public void draw() { + System.out.println("绘制圆形"); + } +} +class Rectangle extends Shape { + @Override + public void draw() { + System.out.println("绘制矩形"); + } +} +public class ShapeDemo { + public static void drawShape(Shape s) { + s.draw(); + } + public static void main(String[] args) { + Shape circle = new Circle(); + Shape rectangle = new Rectangle(); + drawShape(circle); + drawShape(rectangle); + } +} \ No newline at end of file diff --git a/挑战题—Person.txt b/挑战题—Person.txt new file mode 100644 index 0000000..4ff6901 --- /dev/null +++ b/挑战题—Person.txt @@ -0,0 +1,20 @@ +挑战题—Person + +public class PersonManagerTest { + public static void main(String[] args) { + PersonManager manager = new PersonManager(); + Student student1 = new Student("张三", 18, "S001", 95.5); + Student student2 = new Student("李四", 19, "S002", 88.0); + + Teacher teacher1 = new Teacher("王老师", 35, "T001", "数学"); + Teacher teacher2 = new Teacher("李老师", 40, "T002", "英语"); + + manager.addPerson(student1); + manager.addPerson(student2); + manager.addPerson(teacher1); + manager.addPerson(teacher2); + + manager.displayAllPersons(); + manager.processSpecificAttributes(); + } +} \ No newline at end of file diff --git a/进阶题-Vehicle.txt b/进阶题-Vehicle.txt new file mode 100644 index 0000000..9c93adc --- /dev/null +++ b/进阶题-Vehicle.txt @@ -0,0 +1,33 @@ +进阶题——Vehicle +abstract class Vehicle { + public abstract void run(); +} +class Car extends Vehicle { + @Override + public void run() { + System.out.println("汽车在公路上行驶"); + } +} +class Bike extends Vehicle { + @Override + public void run() { + System.out.println("自行车在道路上骑行"); + } +} +class Truck extends Vehicle { + @Override + public void run() { + System.out.println("卡车在高速公路上运输货物"); + } +} +public class VehicleDemo { + public static void main(String[] args) { + Vehicle[] vehicles = new Vehicle[3]; + vehicles[0] = new Car(); + vehicles[1] = new Bike(); + vehicles[2] = new Truck(); + for (Vehicle vehicle : vehicles) { + vehicle.run(); + } + } +} \ No newline at end of file