public class TestDemo 
{
    public TestDemo(String id)
    {
    
    }
    
    public String getID()
    {
     return "";
    }
}
在不添加任何全局变量和类变量的前提下,不改变类的架构
要求:只能在构造方法和方法中添加合适的代码来完成该类的初始化,
怎么做?有高手请回答…… 谢谢

解决方案 »

  1.   

    public class TestDemo 

        public TestDemo(String id) 
        { 
            new TextDemo(string);
        } 
        
        public String getID() 
        { 
        return ""; 
        } 
    }
      

  2.   

    public class TestDemo 

        public TestDemo(String id) 
        { 
        } 
        
        public String getID() 
        { 
           return new TestDemo(String id);  
        } 
    }
      

  3.   

    啥意思
    public class TestDemo 

        public TestDemo(String id) 
        { 
             System.setProperty("key", id);
        } 
        
        public String getID() 
        { 
          return System.setProperty("key");
        }
    }是不是这样的
      

  4.   

    public class TestDemo 

        public TestDemo(String id) 
        { 
            ? = id;
        } 
        
        public String getID() 
        { 
        return ""; 
        }