0% found this document useful (0 votes)
6 views1 page

Java Thread Naming Example

The document presents a Java code snippet that creates two threads named 'Scooby' and 'Shaggy'. Each thread, when started, prints its name to the console. The code demonstrates basic thread creation and naming in Java.

Uploaded by

MADHAV SHARMA
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Java Thread Naming Example

The document presents a Java code snippet that creates two threads named 'Scooby' and 'Shaggy'. Each thread, when started, prints its name to the console. The code demonstrates basic thread creation and naming in Java.

Uploaded by

MADHAV SHARMA
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Q.

Create two threads and assign names ‘Scooby’ and ‘Shaggy’ to the two
threads. Display both thread names.

CODE:
package com.packagep1;

public class Main {

public static void main(String[] args) {


Thread t1 = new Thread("Scooby") {
public void run() {
[Link]("I'm " + [Link]().getName());
}
};

Thread t2 = new Thread("Shaggy") {


public void run() {
[Link]("I'm " + [Link]().getName());

}
};

[Link]();
[Link]();

SS:

You might also like