请看这段代码,并回答问题,谢谢! 
public   class   ShadowTest   {         public   static   void   main(String   s[]){                                 new   STChild().demo();         } } class   STGrandParent   {         double   wealth   =   50000.00;         public   double   getWealth()   {                                 System.out.println( "GrandParent- "   +   wealth);                                 return   wealth;         } } class   STParent   extends   STGrandParent   {         double   wealth   =   100000.00;         public   double   getWealth()   {                                 System.out.println( "Parent- "   +   wealth);                                 return   wealth;         } } class   STChild   extends   STParent   {         double   wealth   =   200000.00; 
        public   double   getWealth()   {                                 System.out.println( "Child- "   +   wealth);                                 return   wealth;         } 
        public   void   demo()   {                                 getWealth();   //   Calls   Child   method                                 super.getWealth();   //   Calls   Parent   method                               super.super.getWealth();   //   1     怎样才能调用父类的父类的方法?                                 ((STParent)this).getWealth();   //   2   。   为什么调用的是本类的而不是父类的方法? 
        ((STGrandParent)this).getWealth();   //   3。为什么调用的是本类的而不是父类的父类的方法? 
                                System.out.println(wealth); 
                                System.out.println(super.wealth); 
                                System.out.println(((STParent)(this)).wealth);   //   4。为什么调用的是父类的属性?                                 System.out.println(((STGrandParent)(this)).wealth);   //5。为什么调用的是父类的父类的属性?         } } 

解决方案 »

  1.   

    首先: 
    this 是指当前的对象
    super 是指当前对象的超类
    其次回答你的问题: 1  怎样才能调用父类的父类的方法?   
    当你的父类中没有getWealth()这个方法的是否可以用super.getWealth()调用父类的父类的方法。因为父类的方法将父类的父类的方法覆盖了~
     2-4 是以个问题;将以个对象强制转换为他的超类时要注意以下两点:1. 将对象转换为超类,调用的方法是从本类开始向上查找。即在本类由该方法则调用本类的方法,没有则调用其父类中的方法
    2. 将对象转换为超类,调用的属性是转换的类的属性