我想在Java中使用同一个对象同时在同一个类中使用2个方法.例如:
public class aThread extends Thread {
int countA = 0;
int countB = 0;
int countA(){
for (int i = 0; i < 1000; i++) {
countA++;
}
return countA;
}
int countB(){
for (int i = 0; i < 1000; i++) {
countB++;
}
return countB;
}
@Override
public void run() {
super.run();
//should there be something here?
}
}
Run Code Online (Sandbox Code Playgroud)
并在另一种方法中使用此方法:
public class MainClass {
public static void main(String[] args) {
aThread myThread = new aThread();
myThread.countA(); //I …Run Code Online (Sandbox Code Playgroud)