herizai
方法重载:一个类中有一个方法A,你又在这个类中创建了一个方法B,方法B的名字和A一样,返回值类型也一样,但是参数的类型或个数不同,此时B重载了A。
例如:
public class TestClass{
    public int test(int i){return 1;}
    public int test(float f){return 1;}
}

  

方法重写:一个类M继承另一个类N,N中有一个方法A,这时你在M写了一个方法B,方法B的名字、返回值以及参数都和A一样,此时B重写了A。 例如:
 public class TestClass1
{
 public int test(int i)
{return 1;} }
 public class TestClass2 extends TestClass1
{ public int test(int i){return 2;} }

  

分类:

技术点:

相关文章:

  • 2021-11-28
  • 2021-12-07
  • 2022-12-23
  • 2021-11-28
  • 2022-02-28
猜你喜欢
  • 2021-11-28
  • 2021-11-28
  • 2021-08-20
  • 2021-06-05
  • 2021-06-27
相关资源
相似解决方案