Yogesh
Yogesh

Reputation: 3

problem in accessing the anonymous class method

I have written this code and this generate the error like Illegal start of expression on the line of run() method ,please solve my problem.

     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();  
            }
        } 

Upvotes: 0

Views: 43

Answers (1)

Rupesh Agrawal
Rupesh Agrawal

Reputation: 695

Change your code,

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

to

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

Upvotes: 1

Related Questions