3. 下面代码正确吗?如有错,请改正
public interface A{
void test();
}public A getA(String s) {
class AImpl implements A{
private String b;
private AImpl() {
b = s;
}
public String getB() {
return b;
}
}
return new AImpl();
}

解决方案 »

  1.   

    类AImpl的构造函数应该是public,并且应该有参数AImpl(String s).
    类AImpl必须实现test()方法.
      

  2.   

    public interface A{
         void test();
        }    public A getA(final String s) {
         class AImpl implements A{
         private String b;
         private AImpl() {
         b =s;
         }
         public String getB() {
         return b;
         }
                public void test() {
                        
                }
     
         }
         return new AImpl();
        }
      

  3.   

    就2个错误:接口A.test()在继承类AImp中必须被实现;method getA()不再具体的类中。
    package others;interface A{
    void test();
    }public class Test{
    public A getA(final String s) {
    class AImp implements A{
    private String b;
    private AImp() {
    b =s;
    //System.out.println(this.b);
    }
    public String getB() {
    return b;
    }
            public void test() {
             //System.out.println("AImp's Test");
                    
            } }
    return new AImp();
    }
    public static void main(String[] args){
    A atest=new Test().getA("test AImp()");
    atest.test();

    }
    }
      

  4.   

    1 接口A.test()在继承类AImp中必须被重载;
    2 method getA()不再具体的类中。
    3 AImp 的构造函数为private 不能创建AImp的对象,必须改为public
      

  5.   

    HOHO~~~~~~~~~~没的说了!楼上说完了。
      

  6.   

    1 方法getA()不在具体的类中
    2 类AImpl的构造函数应该是public类型
    3 类AImpl必须实现接口的test()方法