new A extend B{
//...
}.method();

解决方案 »

  1.   

    按你的要求,
    新类A必须为匿名类,则:
    public class TestInheri
    {
        class B
        {
            void sayHello()
            {
                System.out.println("hello!");
            }
        }
        void test()
        {
            new B(){ }.sayHello();
        }
        public static void main(String[] args)
        {
            new TestInheri().test();
        }
    }
      

  2.   

    “ gdsean(摇滚java) ( ) ”
    在语法上是错误的。是不能通过的。
      

  3.   

    匿名类是不能extends/implements的
      

  4.   

    new A extends B(){}.method();这样子可以吗?
      

  5.   

    回复人: shine333(shine) ( ) 信誉:100  2003-08-19 15:16:00  得分:0 
     
     
      匿名类是不能extends/implements的
     
     
    ========================================================================
    原来是这样啊
    我本来想用DateFormat.parse(string)这个方法的,结果发现DateFormat是abstract的。
    现在我直接用SimpleDateFormat了,SUN想的挺周到的,呵呵