What will be displayed?

public class TestMethods{
	public static void main(String[] args){
		TestMethods test = new TestMethods();
		Thread anotherThread = new Thread("Thread#2"){
			public void run(){
				staticMethod();
			}
		};
		anotherThread.start();
		test.instanceMethod();
	}
	
	public static synchronized void staticMethod(){
		System.out.println("Running static method");
		try{
			Thread.sleep(1000);
		} catch (InterruptedException e){
			System.out.println(Thread.currentThread().getName() + " interrupted!");
		}
		System.out.println("Exiting static method");
	}
	
	public synchronized void instanceMethod(){
		System.out.println("Running instance method");
		try{
			Thread.sleep(1000);
		} catch (InterruptedException e){
			System.out.println(Thread.currentThread().getName() + " interrupted!");
		}
		System.out.println("Exiting instance method");
	}
}

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes