我想在一个线程里调用另外一个类里的一个方法怎么做啊? rt.....想在一个线程里调用另外一个类里的一个方法怎么调用啊?最好是直接调用方法。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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(); }} 最好是:public synchronized void method(){ System.out.println("my name is YourObject!"); } 现在想想,还真可能不同,推荐使用pipedOutputStream java程序求解 接口除了向上转型,还有别的用吗 replaceAll怎么使用呢 那位高手能给解释一下垃圾回收的机制 谁能帮我分析一下这段代码 送分!!调用PL/SQL存储过程问题 哪里有tomcat的好的tutorial或documentation ###用JAVA做聊天室的一个效率问题,请帮忙!### 高考失败----通过高程----可否就业? 短信猫在startService这不执行了,也没报错 把我急着了,要期末了还没搞出来 想要在JMenuItem上加图片
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();
}
}
public synchronized void method(){
System.out.println("my name is YourObject!");
}