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
Write a regular expression to validate a password. A password must start with an alphabet and followed by alphanumeric characters; its length must be in between 8 to 20.
What is difference between jdk,jre and jvm?
What is Java Package and which package is imported by default?
From the two, which would be easier to write: synchronization code for ten threads or two threads?
What is the memory leak in java?
What is tcp ip in java?
What methodology can be employed to locate substrings inside a string?
What is the difference between iterator and list iterator?
What is the disadvantage of java?
What is the difference between instanceof and isinstance?
How to Sort Strings which are given in List and display in ascending order without using java api.
How can constructor chaining be done by using the super keyword?
Name few java 8 annotations ?
Can we nested try statements in java?
What methodology can be utilized to link to a database?