package package3;public class Apple extends Thread{ @Override public void run() { for (int index = 0; index < 5; index++) { System.out.println("thread "+index); } } public void Other(){ for (int index = 0; index < 5; index++) { System.out.println("other "+index); } } public static void main(String... args) { Apple app= new Apple(); app.start(); app.Other(); }}affiche : other 0 thread 0 other 1 thread 1 other 2 thread 2 other 3 thread 3 other 4 thread 4----------------------------------------------------package package3;public class Apple extends Thread{ @Override public void run() { Other(); } public synchronized static void Other(){ for (int index = 0; index < 5; index++) { System.out.println("other "+index); } } public static void main(String... args) { Apple app= new Apple(); app.start(); Apple app2= new Apple(); app2.start(); }}affiche : other 0 other 1 other 2 other 3 other 4 other 0 other 1 other 2 other 3 other 4
package package3;
public class Apple extends Thread{
@Override
public void run() {
for (int index = 0; index < 5; index++) {
System.out.println("thread "+index);
}
public void Other(){
System.out.println("other "+index);
public static void main(String... args) {
Apple app= new Apple();
app.start();
app.Other();
affiche :
other 0
thread 0
other 1
thread 1
other 2
thread 2
other 3
thread 3
other 4
thread 4
----------------------------------------------------
Other();
public synchronized static void Other(){
Apple app2= new Apple();
app2.start();
0 تعليقات