访问匿名类方法时出现问题

时间:2018-09-05 07:03:04

标签: java

我已经编写了这段代码,这会在run()方法的行上生成错误的表达式开头,请解决我的问题。

     class Reentrant 
        {
            public synchronized void m() 
            {
                 n();  
                    System.out.println("this is m() method");  
                }  


            public synchronized void n() 
            {  
                    System.out.println("this is n() method");  
                }
            {  
                public void run(){  
                        m();//calling method of Reentrant class  
                }  
            };  
        }  
        class ReentrantExample
        {  
            public static void main(String args[])
            {  
                Reentrant re=new Reentrant();  

                Thread t1=new Thread();

                t1.start();  
            }
        } 

1 个答案:

答案 0 :(得分:1)

更改代码,

{  
            public void run(){  
                    m();//calling method of Reentrant class  
            }  
        };

  public void run(){  
                    m();//calling method of Reentrant class  
            }