Skip to content

Commit

Permalink
✏更新 Java 继承与多态
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcaffebabe committed Sep 15, 2020
1 parent 5dd4dea commit 6c32c24
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 编程语言/JAVA/高级/继承与多态.md
@@ -1,5 +1,14 @@
# 继承与多态

## 类的定义

1. 先定义变量
2. 后定义方法
1. 公有方法
2. 保护方法
3. 私有方法
4. getter/setter方法

## 继承

> 就是子类继承父类的属性和行为,使得子类对象具有与父类相同的属性、相同的行为。子类可以直接 访问父类中的非私有的属性和行为。
Expand Down Expand Up @@ -96,6 +105,12 @@ class 类名 [extends 父类名] implements 接口名1,接口名2,接口名

- 如果默认方法有重名的,必须重写一次。

## 抽象类与接口

抽象类是is-a关系, 是模板式设计 接口是 can-do关系, 是契约式设计

优先定义接口, 避免直接使用继承

## 多态

```java
Expand Down

0 comments on commit 6c32c24

Please sign in to comment.