自动化的JAVA基础

多态

父类的方法子类可以重写,扩展应用范围

public class Father {
    public void test(){
    System.out.println("this is father");
    }
}
public class Child extends Father {
    public void test(){
        System.out.println("this is Child");
    }

}

方法可以重载,通过采用不同的参数,实现不同的功能,可以是参数个数也可以是参数类型
参数一样返回值不一样的方法是重复方法,会报错

public class TestClass {
    public void test(){
        System.out.println("this is test");
    }

    public void test(String name){
        System.out.println("this is test:"+name);
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_40049311/article/details/80244158
今日推荐