How Thread return a value after finishing its job?

ExecutorService is an interface that extends Executor class and represents an asynchronous execution. It provides us mechanisms to manage the end and detect progress of the asynchronous tasks.
Java Callable tasks return java.util.concurrent.Future object. Using Java Future object, we can find out the status of the Callable task and get the returned Object. It provides get() method that can wait for the Callable to finish and then return the result.

Callable and Future Example in Java

Example

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Main {
public static void main(final String[] args) {
final ExecutorService service;
final Future task;
service = Executors.newFixedThreadPool(5);
task = service.submit(new Foo());
try {
final String str;
str = task.get();
System.out.println(str);
} catch(final InterruptedException ex) {
ex.printStackTrace();
} catch(final ExecutionException ex) {
ex.printStackTrace();
}
service.shutdownNow();
}
}
class Foo implements Callable {
public String call() {
try {
// sleep for 10 seconds
Thread.sleep(10 * 1000);
} catch(final InterruptedException ex) {
ex.printStackTrace();
}
return (“Hello, World!”);
}
}

Method Hiding in java

“Method hiding means subclass has defined a class method with the same signature as a class method in the superclass. In that case the method of superclass is hidden by the subclass.”

public class Super {
public static void foo() {
System.out.println(“Super”);
}
}
public class Child extends Super {
public static void foo() {  // hides Super.foo()
System.out.println(“Child”);
}
}
Here, Child.foo() is said to hide Super.foo().
static methods are not polymorphic

Super.foo(); // prints Super
Child.foo(); // prints Child

Lets examing on non-static scope

Super a = new Super();
Super b = new Child();
Child c = new Child();
Super d = null;

a.foo(); //  Prints Super
b.foo(); //  Prints Super because the declared type of b is Super
c.foo(); //  Prints Child because the declared type of c is Child
d.foo(); //  Prints Super because of static method

if the methods are nonstatic  in Super and child classes then

Super a = new Super();
Super b = new Child();
Child c = new Child();
Super d = null;

a.foo(); // prints Super
b.foo(); // prints Child–> Observe and compare this method call on static and non-                                                                                                                                    static scenarios
c.foo(); // prints Child
d.foo(): // throws NullPointerException