zoukankan      html  css  js  c++  java
  • 方法重载与方法重写的概念和区别(转载)

    方法重载:一个类中有一个方法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;} }
    

      

  • 相关阅读:
    程序猿小白博客报道
    UML
    mysql隔离级别相关
    mac使用相关笔记
    git相关
    maven相关
    springboot相关
    guava
    IDEA高效运用技巧
    spring事务相关
  • 原文地址:https://www.cnblogs.com/herizai/p/6905176.html
Copyright © 2011-2022 走看看