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 serialization and deserialization in java?
Is null == null in java?
What is the difference between a method and a function in alice?
What is a map in java?
What do you mean by data type?
Can we overload the methods by making them static?
What do you mean by platform independence of Java?
Can we override private method in java?
Explain importance of throws keyword in java?
how can you catch multiple exceptions in java?
What is java Applet?
What is thread start?
What languages are pass by reference?
What is the difference between conversation & casting?
What is the difference between dom and sax parser in java?