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
Explain the features of java?
Can we start a thread twice in java?
Can we call the constructor of a class more than once for an object?
Can we assign null to double in java?
What is scope & storage allocation of global and extern variables? Explain with an example
What is the function of compareto in java?
What is the java idl system?
What do you mean by global variable?
What is the final field modifier?
Why collection is called framework in java?
Explain the init method?
Distinguish between a predicate and a function?
Is a method a function?
placement papaers of spring computing technology
What was java originally called?