zoukankan      html  css  js  c++  java
  • JAVA面向对象的学习 -------多态 Instance of 的学习(类型转换)

    public static void main(String[] args) {
    //类型之间的转换 父 到 子 高 到 低
    Person person = new Student();
    //student这个对象装换为Student类型,我们就可以使用Student类型的方法了
    Student student = (Student) person;//<===>((Student) person).go();
    student.go();


    //子 到 父 子类转换为父类,可能会丢失一些自己的方法
    Student S1 = new Student();
    Person P1 = student;
    //P1.go(); 父类转换为子类可能会丢失方法
    }


    }


    /*
    1.父类的引用指向子类的对象.
    2.把子类转换为父类,向上转型;
    3.把父类转换为子类,向下转型;强制转换, 会丢失方法
    4.方便方法的调用,减少重复的代码。简洁


    抽象: 封装, 继承 ,多态 。 抽象类 , 接口。
    */



  • 相关阅读:
    不死神兔
    C/C++内存管理详解
    python下调用不在环境变量中的firefox
    【转至nmap】nc命令
    Linux SSH隧道技术(端口转发,socket代理)
    linux共享上网设置
    HDU
    CSU
    HDU
    HDU
  • 原文地址:https://www.cnblogs.com/acg-lbj/p/13269671.html
Copyright © 2011-2022 走看看