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);} }
?