有这样一个问题:父类parent.class 
          设置描述信息       
 //其中description 声明为private类型
 private String description;
 public void setDescription(String s)
        throws WTPropertyVetoException
    {
        descriptionValidate(s);
        description = s;
    }    private void descriptionValidate(String s)
        throws WTPropertyVetoException
    {
      ........
    }
那么在它的继承类中要怎么重写setDescription(String s)方法.使得:如果description为null,设置为空格(前提是parent.class 不能修改)

解决方案 »

  1.   

    不可能
    要不Java的封装不是变成了形同虚设了嘛?
      

  2.   

    如果是C++,就是Pach一下我也帮你了Java受不了
      

  3.   

    可以啊 你在父类里面写一个自定义够造方法啊
    然后子类覆盖的时候调用super(String s);
      

  4.   

    你试试看
    你在父类里面写一个自定义够造方法用来初始化description;
    然后子类覆盖的时候调用super(String s);刚刚写的不全
      

  5.   

    这里我要做的就是利用Java里的Object的灵活性,代码如下:你看看行不行 
    public void setDescription(Object s)
            throws WTPropertyVetoException
        {
            if(s==null){
                description==" ";//设成空格
              }
            else{
            descriptionValidate(s);
            description = s;
             }
         }
    不知道这样做合不合你的需求
      

  6.   

    好像问题说的不清楚?
    应该是楼上那样深圳java程序员博客,为你提供多方面资料http://drivemewild.blogchina.com
      

  7.   

    看看是不是可以在父类中增加一个get方法,然后再子类中的set方法中加入父类的get方法判断