java 对象的上转型对象(父类)
生活随笔
收集整理的這篇文章主要介紹了
java 对象的上转型对象(父类)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Example5_10.java
class 類人猿 {void crySpeak(String s) {System.out.println(s); } } class People extends 類人猿 {void computer(int a,int b) { int c=a*b;System.out.println(c); }void crySpeak(String s) {System.out.println("***"+s+"***"); } } public class Example5_10 {public static void main(String args[]) {類人猿 monkey=new People(); //monkey是People對象的上轉型對象monkey.crySpeak("I love this game");People people=(People)monkey; //把上轉型對象強制轉化為子類的對象people.computer(10,10);} }?
轉載于:https://www.cnblogs.com/yihujiu/p/5990608.html
總結
以上是生活随笔為你收集整理的java 对象的上转型对象(父类)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用MJRefresh自定义下拉刷新,上
- 下一篇: BZOJ 1012 单调队列+二分