0% found this document useful (0 votes)
2 views2 pages

12 Program

The document describes a Java program that demonstrates the use of threads by creating a class 'MyThreadNew' that extends the Thread class. It includes a constructor that calls the base class constructor and starts the thread immediately. The run method of 'MyThreadNew' prints the thread name and a count, while the main method creates an instance of 'MyThreadNew' and also prints the main thread's name and count concurrently.

Uploaded by

gowdavikas2123
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

12 Program

The document describes a Java program that demonstrates the use of threads by creating a class 'MyThreadNew' that extends the Thread class. It includes a constructor that calls the base class constructor and starts the thread immediately. The run method of 'MyThreadNew' prints the thread name and a count, while the main method creates an instance of 'MyThreadNew' and also prints the main thread's name and count concurrently.

Uploaded by

gowdavikas2123
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
BCS306A class a constructor, call the base class arts afterthis. It can be OOPS WITH JAVA LAB jevelop a program to create a cla: constructor, using super and start the th observed that both main thread and created chitd th 'ss MyThread in this tread, The run method of the class st read are executed. Concurrently. Program: class MyThreadNew extends Thread { // Constructor calling base class constructor using super public MyThreadNew(String name) { super(name); start(); // Start the thread in the constructor } // The run method that will be executed when the threa @Override public void run() { d starts for (int i= 1; 1<=5; i++) { [Link](Thr try{ [Link]().getName() +" Count: " +i); [Link](500); // Sleep for 500 milliseconds } catch (InterruptedException e){ [Link]([Link]).getName() +" Thread interrupted."); By jpublic class Progrram12 { public static void main(String[] args) { // Create an instance of MyThread MyThreadNew myThread = new MyThreadNew("Child Threa // Main thread for (int i= 1;1<= 5; i+) { ‘[Link]([Link]().getName() + " Thread Count: " + i) Try { [Link](500); // Sleep for 500 milliseconds }eatch (InterruptedException e) { [Link]([Link]().getName() + " Thread interrupted."); » — —__ a Page 30

You might also like