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
Why Set interface contains unique elements, what internally implemented for this so that it contains unique elements?
What are instance variables?
Why to use nested classes in java? (Or) what is the purpose of nested class in java?
Can we declare an array without size in java?
Define Multiprogramming and Multiprocessing in java.
What is the use of callablestatement?
What is volatile keyword in java
What is function and method in java?
What is output buffer?
What are recursive functions?
If a variable is declared as private, where may the variable be accessed?
Why java is used everywhere?
Why is a singleton bad?
What does the “static” keyword mean? Can you override private or static method in java?
What is object data type?