我想在一个线程里调用另外一个类里的一个方法怎么做啊? rt.....想在一个线程里调用另外一个类里的一个方法怎么调用啊?最好是直接调用方法。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 就可以把另外一个类的方法声明成 public static 的,或者,将另一个类的对象作为参数传进去就可以了 class Thread1 extend Thread{ private YourObject o; public Thread1(YourObject o){ this.o=o; } public void run(){ o.method(); }}class YourObject { public void method(){ System.out.println("my name is YourObject!"); }}public class Test{ public static void main(String args[]){ YourObject o=new YourObject(); Thread n=new Thread1(o); n.start(); }} Java如何实现缩略图???急救!!!! 关于外部类属性访问、键盘事件、文本实时更新的问题 动态多态为什么不适用与静态方法 怎么对oracle中的clob类型进行操作? socket 基础问题 关于java事件 如何用executeUpdate插入数据的值 学到实例和静态的小小疑问 请各位大虾帮帮忙! Java菜鸟求教 如何将输入Reader流的数据读取到char数组中? 内部类做监听器的问题<anonymous myframe$1> is not abstract and does not override abstract method actionPerformed
private YourObject o;
public Thread1(YourObject o){
this.o=o;
}
public void run(){
o.method();
}
}class YourObject {
public void method(){
System.out.println("my name is YourObject!");
}
}
public class Test{
public static void main(String args[]){
YourObject o=new YourObject();
Thread n=new Thread1(o);
n.start();
}
}