explain me with a code snippet about the generation and
handling of null point exceptions.



explain me with a code snippet about the generation and handling of null point exceptions...

Answer / g.arun

class Test
{
public static void main(String[] args)
{
try
{
int a[] = null;
System.out.println(a.length);
}
catch (NullPointerException n)
{
System.out.println(n);
}

}
}
U can try this by changing NullPointerException in catch
block as catch(Exception e){ System.out.println(n);}

and Using throw it is

class Test
{
public static void main(String[] args)
{
int a[] = null;
System.out.println(a.length);
NullPointerException n = new NullPointerException();
throw n;
}
}

Using Throws

class Test
{
public static void main(String[] args) throws
Exception
{
int a[] = null;
System.out.println(a.length);
}
}

That's all friends hope this one helps you

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

Why main method is called first in java?

0 Answers  


Which method is used to find that the object is exited or not?

2 Answers  


Is minecraft 1.15 out?

0 Answers  


Is arraylist ordered?

0 Answers  


What is appletviewer?

0 Answers  






Explain the difference between throw and throws in java?

0 Answers  


How to find the size of an array a)array.length() b)array.length c)array.size() d)array.size

6 Answers   Accenture,


If all the methods in abstract class are declared as abstract then what is difference between abstract class and in interface?

8 Answers   Infosys, Synechron,


Do you need to import math in java?

0 Answers  


Is c better than java?

0 Answers  


What is java util collection?

0 Answers  


Why string is not thread safe?

0 Answers  


Categories