Menu
Question Index
...

What is the output of the following program?

import java.util.concurrent.*;
public class CocurrencyTest {
    public static void main(String[] args) {
        ExecutorService es = Executors.newFixedThreadPool(3);
        Future<Double> f = (Future<Double>) es.submit(new ClassB(2.0, 2));
        Future<Integer> f1 = es.submit(new ClassA(5));
        Future<Integer> f2 = es.submit(new ClassC(3));
        try {
            System.out.print(f1.get() + " ");
            f.get();
            System.out.println(f2.get());
        } catch (Exception e) {  }
    }
}
class ClassA implements Callable<Integer> {
    int E;
    public ClassA(int i) { E = i; }
    public Integer call() throws Exception {
        int result = 0;
        for (int i = 0; i < E; i++) {result += i; }
        return result;
    }
}
class ClassB implements Runnable {
    double s;
    double e;
    public ClassB(double s, double e) { this.s = s; this.e = e; }
    public void run() { System.out.print(Math.sqrt(s + e) + " "); }
}
class ClassC implements Callable<Integer> {
    int E;
    public ClassC(int i) { E = i;  }
    public Integer call() throws Exception {
        int result = 1;
        for (int i = 1; i < E; i++) { result *= i;  }
        return result;
    }
}


2.0 10 6
10 2.0 2
2.0 10 2
Compiles and executes without any output
output cannot be determined.
Compilation Error or Runtime Error

Doubts

Problems

Topic: Other Advanced Topics In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App