Menu
Question Index
...

What will be the output of the following program?

public class SynchronizedExample {
    public static void main(String[] args) {
        Callme target = new Callme();
        Caller obj1 = new Caller(target, "Hello");
        Caller obj2 = new Caller(target, "Synshronized");
    }
}
class Callme {
    synchronized void call(String msg) {
        System.out.print("[" + msg);
        System.out.print("]");
    }
}
class Caller implements Runnable {
    String msg;
    Callme target;
    Thread t;
    public Caller(Callme targ, String s) {
        target = targ;
        msg = s;
        t = new Thread(this);
        t.start();
    }
    public void run() {
        target.call(msg);
    }
}


[Hello][Synshronized]
[Hello[Synshronized]]
Output can not be determined
Compilation Error or Runtime Error

Doubts

Problems

Topic: Thread Synchronization In Java Using 'Synchronized'

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App