From d9b2ac5d01163ca45b84ead150a6119e26ee0593 Mon Sep 17 00:00:00 2001 From: Chris Qi Date: Tue, 3 Nov 2020 09:03:05 +0000 Subject: [PATCH 1/2] Added more details about overloading --- docs/notes/Java 基础.md | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/docs/notes/Java 基础.md b/docs/notes/Java 基础.md index f30239f5..ec6bee09 100644 --- a/docs/notes/Java 基础.md +++ b/docs/notes/Java 基础.md @@ -1323,6 +1323,55 @@ public static void main(String[] args) { 应该注意的是,返回值不同,其它都相同不算是重载。 +- 方法重载 例子 +```java +class DisplayOverloading +{ + public void disp(char c) + { + System.out.println(c); + } + public void disp(char c, int num) + { + System.out.println(c + " "+num); + } +} +class Sample +{ + public static void main(String args[]) + { + DisplayOverloading obj = new DisplayOverloading(); + obj.disp('a'); + obj.disp('a',10); + } +} +``` +[Method Overloading](https://beginnersbook.com/2013/05/method-overloading/#:~:text=Method%20Overloading%20is%20a%20feature,constructor%20having%20different%20argument%20lists.) + +- 构造重载 例子 +```java +class DisplayOverloading +{ + DisplayOverloading(char c) + { + System.out.println(c); + } + DisplayOverloading(char c, int num) + { + System.out.println(c + " "+num); + } +} +class Sample +{ + public static void main(String args[]) + { + DisplayOverloading obj = new DisplayOverloading('a'); + DisplayOverloading obj2 = new DisplayOverloading('a',10); + } +} +``` +[Constructor Overloading](https://beginnersbook.com/2013/05/constructor-overloading/) + # 七、反射 每个类都有一个 **Class** 对象,包含了与类有关的信息。当编译一个新类时,会产生一个同名的 .class 文件,该文件内容保存着 Class 对象。 From a18c1088c892f1e6ed4b7d541e68b2e4b039a42e Mon Sep 17 00:00:00 2001 From: qizhengzhong <47613322+qizhengzhong@users.noreply.github.com> Date: Tue, 3 Nov 2020 09:06:57 +0000 Subject: [PATCH 2/2] Update the link to simpler version --- docs/notes/Java 基础.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/notes/Java 基础.md b/docs/notes/Java 基础.md index ec6bee09..9ed0ebaa 100644 --- a/docs/notes/Java 基础.md +++ b/docs/notes/Java 基础.md @@ -1346,7 +1346,7 @@ class Sample } } ``` -[Method Overloading](https://beginnersbook.com/2013/05/method-overloading/#:~:text=Method%20Overloading%20is%20a%20feature,constructor%20having%20different%20argument%20lists.) +[Method Overloading](https://beginnersbook.com/2013/05/method-overloading/) - 构造重载 例子 ```java