this的问题
你加注释之前,它输出的是Glyph的radius
去掉注释以后,Glyph没有radius了,输出的是RoundGlyph的radius
如果要保证两次输出都一致的话,使用this.radius

解决方案 »

  1.   

    奇怪,我无论是否注释都得到同样的结果
    Glyph() before draw()
    RoundGlyph.draw(),radius= 0
    Glyph() after draw()
    RoundGlyph.RoundGlyph(),radius= 6
    你的
    Glyph() before draw()RoundGlyph.draw(),radius= 2Glyph() after draw()RoundGlyph.RoundGlyph(),radius= 6
    是这么得到的?
      

  2.   

    同意“见到PLMM脸就红”他们的结果是一致的!不过我现在不明白在抽象类中貂调用抽象方法会有什么结果?或者说他们的具体到底调用的是那个类的方法。
      

  3.   

    明白你的意思了,我刚才没注释RoundGlyph 类里面的radius注释掉以后结果是你那样的
      

  4.   

    ?a?ú3?ê??ˉ?3DòóD1??£°?×óàà?Dμ?×??????a static£??í?éò?á?abstract class Glyph{
    //     int radius=2;//????×¢êí
         abstract void draw();
         Glyph(){
             System.out.println("Glyph() before draw()");
             draw();
             System.out.println("Glyph() after draw()");
          }
     } class RoundGlyph extends Glyph{
         public static int radius=1;
         RoundGlyph(int r){
           super();
    //       draw();
           System.out.println("radius = "+radius);
             radius=r;
             System.out.println("RoundGlyph.RoundGlyph(),radius= "+radius);
         }
        
         void draw(){
             System.out.println("RoundGlyph.draw(),radius= "+radius);
         }
     }public class PolyConstructors {  public static void main(String[] args)
          {
          new RoundGlyph(6);
          }
    }ê?3??á1??a£o
    Glyph() before draw()
    RoundGlyph.draw(),radius= 1
    Glyph() after draw()
    radius = 1
    RoundGlyph.RoundGlyph(),radius= 6?1???êò???£?????òaê2?′?á1?£?
    3L3€??=u犘=u0I許?(8=u?8=u??=u?怓??=u??=u?%=u許?P?up8=uH=uh- 垳笢 ` ? 犦ㄝ 0ル4ル?T.??=uPI=u(阱€P?? 

    ?
    X!藅?藅?藅|D藅3B藅峢藅唄藅a!藅;藅Qg藅p藅VF藅蜤藅J5藅?藅p€藅抙藅Ok藅o藅 藅藅 逅t忮藅磬藅礵藅藅€!衒>
    %=u€!萣^??x皲? 211.157.102.22@B.22?xtCSDNSQL102.22€? &疝? 痞 select top 300 TopicId, TopicNme, PostUserName, ReplyNum,endstate,ReplyDateTime, Point  from Expert_Topic_Index where (point >= 0)  and roomid =  28   and Topicsdnwebke  '%sql%'   order by replydatetime desc &€&€&and a.KeysWord like '%linux Njsp痵僗刧鷁%'  order by a.Topic_Id desc &€dfgh5678csdn
    正确的答案  赞成  反对  正确指数: 0   
     
    作者:f.inzaghi 时间:2002-4-17 17:06:00 来自:61.188.xxx.xxx 
     
    把输入法切换为全角
     
     
    ? ?? ?? ?? ?? ?? ? tintMicrosoft(R) Windows (R) 2000 Operating System   CSDNWEB   ?  Sujus_english
    8  ?  ? lt_csdn
    L?
    竮P&=u`&=u€&=u?=u?=u?=u?=u?=u'=u'=u '=u0'=u@'=u`'=up'=u?=u?=u?=u?=u(=u(=u (=u0(=u@(=up(=u€(=u?=u?=u?=u?=u?=u?=u?=u*=u`*=up*=u€*=u?=u?=u i?
    8 ishCS `?H蒗 裸409 < DBNETLIB nd .Ro  ?     
    8  tint b ubjct_        ?  Sujec
    8  ?  ?  
    L,?
    竮P&=u`&=u€&=u?=u=u?=u?=u?=u'=u'=u '=u0'=u@'=u`'=up'=u?=u?=u?=u?=u(=u(=u (=u0(=u@(=up(=u€(=u?=u?=u?=u?=u?=u?=u?=u*=u`*=up*=u€*=u?=u?=u i?
    8 ishCS `?H蒗 裸409 <  nd .Ro  ?  ?#€? 蘴ConnectionRead (recv()).heckforData()).ConnectionRead (recv()).heckforData()).`qqMicrosoft SQL Server
      

  5.   

    不好意思我,我写错了,应该是下面这样:
    abstract class Glyph{
     //int radius=2;//注释
     abstract void draw();
     Glyph(){
     System.out.println("Glyph() before draw()");
     draw();
     System.out.println("Glyph() after draw()");
     }
     } class RoundGlyph extends Glyph{
     int radius=1;
     RoundGlyph(int r){
     radius=r;
     System.out.println("RoundGlyph.RoundGlyph(),radius= "+radius);
     } void draw(){
     System.out.println("RoundGlyph.draw(),radius= "+radius);
     }
     }public class PolyConstructors {  public static void main(String[] args)
      {
      new RoundGlyph(6);
      }
    }
    这时的输出是:
    Glyph() before draw()RoundGlyph.draw(),radius= 0Glyph() after draw()RoundGlyph.RoundGlyph(),radius= 6
    取消注释后的输出仍然是一样,我不知道为什么第一中情况在RoundGlyph中定义了的radius=1,而结果却仍然是0,但在第二中情况在Glyph定义了radius=2,但结果仍然是一样!我不明白?
      

  6.   

    现在想说明的就是当初你怀疑对了,就是初始话的问题,具体来说是初始化的顺序问题。可能你想让两次分别输出
    RoundGlyph.draw(),radius= 1
    RoundGlyph.draw(),radius= 2但事实上在执行draw()的时候radius只定义了,还没初始化。至于为什么是“0”,我也不是很肯定。你现在想得到什么样的结果?