Skip to content

Commit

Permalink
Merge pull request #168 from lanqiao-courses/20240126-515458-02
Browse files Browse the repository at this point in the history
修复代码结构问题
  • Loading branch information
taotao616 authored Jan 26, 2024
2 parents bda7037 + 6c0bf00 commit a1711de
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions 1230-Java-简明教程-free/03-9467-面向对象.sy.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,8 @@ public class Animal {

```java
public class Dog extends Animal {
//重写父类的bark方法
public void bark() {
//重写父类的bark方法
public void bark() {
System.out.println("汪!汪!汪!");
}
}
Expand All @@ -657,15 +657,15 @@ public class Dog extends Animal {
```java
public class Test{
public static void main(String args[]){
Animal a = new Animal(); // Animal 对象
Animal a = new Animal(); // Animal 对象
Dog d = new Dog(); // Dog 对象

Animal b = new Dog(); // Dog 对象,向上转型为Animal类型,具体会在后面的内容进行详解
Animal b = new Dog(); // Dog 对象,向上转型为Animal类型,具体会在后面的内容进行详解

a.bark();// 执行 Animal 类的方法
d.bark();//执行 Dog 类的方法
b.bark();//执行 Dog 类的方法
}
a.bark();// 执行 Animal 类的方法
d.bark();//执行 Dog 类的方法
b.bark();//执行 Dog 类的方法
}
}
```

Expand Down Expand Up @@ -723,7 +723,7 @@ class Animal {

class Dog extends Animal {

//子类重写父类的bark方法
//子类重写父类的bark方法
public void bark() {
System.out.println("汪、汪、汪!");
}
Expand Down

0 comments on commit a1711de

Please sign in to comment.