#include#include void thread_function() { std::cout << "hello thread\n"; } int main() { std::thread t(thread_function); // create a thread t.join(); // wait for the thread to finish return 0; }
public class MyThread extends Thread { public void run() { System.out.println("Hello from MyThread!"); } } public class Main { public static void main(String[] args) { MyThread thread = new MyThread(); thread.start(); } }In this example, the `MyThread` class extends the `Thread` class and overrides the `run()` method to print a message. Then, an instance of `MyThread` is created and started using the `start()` method. JavaThread is a part of the core Java library, so no explicit package needs to be imported.