Merge pull request #1008 from qizhengzhong/master

增加了方法重载和构造重载的例子
This commit is contained in:
CyC2018 2020-11-04 00:31:07 +08:00 committed by GitHub
commit f80486b832
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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/)
- 构造重载 例子
```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 对象