Runnable r2=new Runnable(){
public void run(){
就在这儿run()方法内部,我需要调用CommonClass下的print()方法,开始的时候我没有将对象cc说明为静态的。MyEclipse就一直提示错误,不让我过去,提示说只有将cc改为静态的才可以通过,难道在实现run()的时候要使用其它类的方法的时候一定要是静态的么????
cc.print("getName()="+cr.getName());
}
};
runnable 为什么能这么用
runnable 不是接口吗,为什么能有run方法,不明白求解释
public void run(){
就在这儿run()方法内部,我需要调用CommonClass下的print()方法,开始的时候我没有将对象cc说明为静态的。MyEclipse就一直提示错误,不让我过去,提示说只有将cc改为静态的才可以通过,难道在实现run()的时候要使用其它类的方法的时候一定要是静态的么????
cc.print("getName()="+cr.getName());
}
};
runnable 为什么能这么用
runnable 不是接口吗,为什么能有run方法,不明白求解释
};
我的意思是为什么能有这个方法体,多线程这一块用的比较少。还请高手指教
看来楼主还是没明白 线程是干什么的?是怎样运行的
百度 java线程
在某些情况下,我们只需要内部类的一个对象,那么我们就没有必要给内部类命名,没有名字的内部类我们称为匿名内部类
public class A extends Applet
{ public void init( )
{ addMouseListener( new B( ) );
}
class B extends MouseAdapter
{ public void mousePressed(MouseEvent me)
{ showStatus("Mouse Pressed."); }
}
}
http://www.java3z.com/cwbwebhome/article/article2/2791.html