Answer Posted / shaik baji
We can the Thread in two ways as follows
1) By implements the "Runnable" Interface
For Example:
class ThreadDemo implements Runnable
{
public static void main(String[] args)
{
Thread t = new Thread(new ThreadDemo());
t.start();
System.out.println("End of main thread");
}
public void run()
{
for(int i=1; i<=10; i++)
System.out.println(i);
System.out.println("End of child thread");
}
}
2) By extents the "Thread" class
NOTE: Thread is not a abstract class.
For Example:
------------
class ThreadDemo extends Thread
{
public static void main(String[] args)
{
Thread t = new ThreadDemo();
t.start();
System.out.println("End of main thread");
}
public void run()
{
for(int i=1; i<=10; i++)
System.out.println(i);
System.out.println("End of child thread");
}
}
| Is This Answer Correct ? | 7 Yes | 2 No |
Post New Answer View All Answers
What is continuity of a function?
what is mena by object block any what is the use of that
What is the effect of keeping a constructor private?
What is __ init __ functions?
Name the components that are termed to be Heavy-weight component but available in Light-weight components?
What is diamond operator in java?
Can a hashset contain duplicates java?
What is the difference between super class & sub class?
What is the instance of an object?
who can i handle multiple client in RMI
What is meant by class loader? How many types are there?
What are different types of multitasking?
What is method overriding in java ?
Write a program in java to calculate the difference between the sum of the odd level and even level nodes of a binary tree.
Explain the private field modifier?