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

Which class has no duplicate elements?

8 Answers  


What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?

0 Answers  


In what type of containers, Border layout is a default layout?

3 Answers  


Does sprintf allocate memory?

0 Answers  


How can you say java is object oriented?

0 Answers  






how can we use the servlet as standalone apllication?should we need to extend any class?

2 Answers   Logica CMG,


What is java util concurrentmodificationexception?

0 Answers  


Is java free for commercial?

0 Answers  


What happens if I remove static from main method?

0 Answers  


What is polymorphism java example?

0 Answers  


What does ide stand for?

0 Answers  


Can a class be private?

0 Answers  


Categories