1) Pls chck the code below:
public class FirstThread
{
public static void main(
String[] args){
MyThread t=new MyThread();
t.start();
}
}
class MyThread extends
Thread {
public void run()
{
for (int x=0; x<5;x++)
System.out.println("In MyThread");
}
}
I tried run() method of MyThread from within itself using t.start().
But it didn’t work. Why this happened? Pls see the code below.
class MyThread extends Thread
{
public void run()
{
for (int x=0; x<5;x++)
System.out.println("In MyThread");
}
public static void main(String[] args){
MyThread t=new MyThread();
t.start();
}
}
Why it cant create new call stack within itself.
2)
Shd program handle NullPointerException using try/catch block.
If no why. And what happens if we try to handle it as its unchecked runtime exception.
3) why cant we use SOP like this:
class TrySOP{
int i;
System.out.println(“hi I m inside class”
;
public static void main(String[] args){
}
}
4) why wait(), notify() and notifyAll() are included as part of
java.lang.Object and not in java.lang.Thread class
5) how does throws clause work.
If we invoke a method from main and suppose it throws NumberFormatException
is it necessary for main method to handle/declare to be thrown.